2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef XWALK_COMMON_LOGGER_H_
18 #define XWALK_COMMON_LOGGER_H_
24 #define LOGGER_TAG "XWALK"
26 #define _LOGGER_LOG(prio, fmt, args...) \
27 LOG_(LOG_ID_MAIN, prio, LOGGER_TAG, fmt, ##args)
29 #define _LOGGER_SLOG(prio, fmt, args...) \
30 SECURE_LOG_(LOG_ID_MAIN, prio, LOGGER_TAG, fmt, ##args)
32 #define LoggerD(fmt, args...) _LOGGER_LOG(DLOG_DEBUG, fmt, ##args)
33 #define LoggerI(fmt, args...) _LOGGER_LOG(DLOG_INFO, fmt, ##args)
34 #define LoggerW(fmt, args...) _LOGGER_LOG(DLOG_WARN, fmt, ##args)
35 #define LoggerE(fmt, args...) _LOGGER_LOG(DLOG_ERROR, fmt, ##args)
37 #define SLoggerD(fmt, args...) _LOGGER_SLOG(DLOG_DEBUG, fmt, ##args)
38 #define SLoggerI(fmt, args...) _LOGGER_SLOG(DLOG_INFO, fmt, ##args)
39 #define SLoggerW(fmt, args...) _LOGGER_SLOG(DLOG_WARN, fmt, ##args)
40 #define SLoggerE(fmt, args...) _LOGGER_SLOG(DLOG_ERROR, fmt, ##args)
45 class LogMessageVodify {
48 void operator&(const std::ostream&) const {}
53 LogMessage(int severity, const char* tag,
54 const char* file, const char* func, const int line)
55 : severity_(severity), tag_(tag), file_(file), func_(func), line_(line) {}
56 LogMessage(int severity, const char* tag)
57 : severity_(severity), tag_(tag), file_(NULL), func_(NULL), line_(0) {}
60 __dlog_print(LOG_ID_MAIN, severity_, tag_,
62 file_, func_, line_, stream_.str().c_str());
64 __dlog_print(LOG_ID_MAIN, severity_, tag_, "%s", stream_.str().c_str());
67 std::ostream& stream() { return stream_; }
74 std::ostringstream stream_;
82 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
85 #define LOGGER(severity) \
86 common::utils::LogMessageVodify() & \
87 common::utils::LogMessage(DLOG_ ## severity, LOGGER_TAG, \
88 __MODULE__, __FUNCTION__, __LINE__).stream()
90 #define LOGGER_RAW(level, tag) \
91 common::utils::LogMessageVodify() & \
92 common::utils::LogMessage(level, tag).stream()
95 #endif // XWALK_COMMON_LOGGER_H_