2 * Copyright (c) 2011 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.
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of log system
26 #warning Please define LOG_TAG
27 #define LOG_TAG "WRT_UNDEFINED"
32 #include <dpl/availability.h>
33 #include <dpl/singleton.h>
34 #include <dpl/noncopyable.h>
35 #include <dpl/free_deleter.h>
44 const char *LocateSourceFileName(const char *filename);
45 std::string FormatMessage(const char *message,
48 const char *function);
54 bool m_isLoggingEnabled;
55 std::unique_ptr<char[],free_deleter> m_tag;
58 bool IsLoggingEnabled() const;
65 void Debug(const char *message,
69 const char *tag = NULL);
74 void Info(const char *message,
78 const char *tag = NULL);
83 void Warning(const char *message,
87 const char *tag = NULL);
92 void Error(const char *message,
96 const char *tag = NULL);
99 * Log pedantic message
101 void Pedantic(const char *message,
102 const char *filename,
104 const char *function,
105 const char *tag = NULL);
108 * Set default's DLOG provider Tag
110 void SetTag(const char *tag);
115 * Log system singleton
117 typedef Singleton<LogSystem> LogSystemSingleton;
122 * Logging API for C++
123 * This API print out messages to the main log buffer
126 #ifdef DPL_LOGS_ENABLED
127 #define DPL_MACRO_FOR_LOGGING(message, function) \
129 std::ostringstream platformLog; \
130 platformLog << message; \
131 DPL::Log::LogSystemSingleton::Instance().function( \
132 platformLog.str().c_str(), \
133 __FILE__, __LINE__, __FUNCTION__, \
137 #define DPL_MACRO_FOR_LOGGING(message, function) do { } while (0)
140 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
141 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
142 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
143 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
144 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)
149 * This API print out messages to the system log buffer
151 #define INTERNAL_SECURE_LOG __extension__ SECURE_SLOG
152 #ifdef DPL_LOGS_ENABLED
153 #define WRT_LOG_(priority, ...) \
155 INTERNAL_SECURE_LOG(priority, LOG_TAG, __VA_ARGS__); \
158 #define WRT_LOG_(priority, ...) do { } while (0)
161 #define WrtLogD(...) WRT_LOG_(LOG_DEBUG, __VA_ARGS__)
162 #define WrtLogI(...) WRT_LOG_(LOG_INFO, __VA_ARGS__)
163 #define WrtLogW(...) WRT_LOG_(LOG_WARN, __VA_ARGS__)
164 #define WrtLogE(...) WRT_LOG_(LOG_ERROR, __VA_ARGS__)
169 * This API print out messages to the system log buffer
172 #define SECURE_SLOGD(fmt, arg...) SLOGD(fmt,##arg)
176 #define SECURE_SLOGW(fmt, arg...) SLOGW(fmt,##arg)
180 #define SECURE_SLOGE(fmt, arg...) SLOGE(fmt,##arg)
187 #ifdef DPL_LOGS_ENABLED
188 #define _D(fmt, arg ...) SECURE_SLOGD(fmt, ##arg)
189 #define _W(fmt, arg ...) SECURE_SLOGW(fmt, ##arg)
190 #define _E(fmt, arg ...) SECURE_SLOGE(fmt, ##arg)
192 #define _D(fmt, arg ...) do { } while (0)
193 #define _W(fmt, arg ...) do { } while (0)
194 #define _E(fmt, arg ...) do { } while (0)