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 "ELECTRON"
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,
58 : severity_(severity), tag_(tag), file_(file), func_(func), line_(line) {}
59 LogMessage(int severity, const char* tag)
60 : severity_(severity), tag_(tag), file_(NULL), func_(NULL), line_(0) {}
63 __dlog_print(LOG_ID_MAIN, severity_, tag_, "%s: %s(%d) > %s", file_,
64 func_, line_, stream_.str().c_str());
66 __dlog_print(LOG_ID_MAIN, severity_, tag_, "%s", stream_.str().c_str());
69 std::ostream& stream() { return stream_; }
77 std::ostringstream stream_;
85 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
88 #define LOGGER(severity) \
89 common::utils::LogMessageVodify() & \
90 common::utils::LogMessage(DLOG_##severity, LOGGER_TAG, __MODULE__, \
91 __FUNCTION__, __LINE__) \
94 #define LOGGER_RAW(level, tag) \
95 common::utils::LogMessageVodify() & \
96 common::utils::LogMessage(level, tag).stream()
98 #endif // XWALK_COMMON_LOGGER_H_