Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / log / include / dpl / log / log.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        log.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of log system
21  */
22 #ifndef DPL_LOG_H
23 #define DPL_LOG_H
24
25 #ifndef LOG_TAG
26 #warning Please define LOG_TAG
27 #define LOG_TAG "WRT_UNDEFINED"
28 #endif
29
30 #include <dlog.h>
31 #include <sstream>
32 #include <dpl/availability.h>
33 #include <dpl/singleton.h>
34 #include <dpl/noncopyable.h>
35 #include <dpl/free_deleter.h>
36
37 namespace DPL {
38 namespace Log {
39 /**
40  * DPL log system
41  *
42  * @deprecated
43  */
44 const char *LocateSourceFileName(const char *filename);
45 std::string FormatMessage(const char *message,
46                           const char *filename,
47                           int line,
48                           const char *function);
49
50 class LogSystem :
51     private Noncopyable
52 {
53   private:
54     bool m_isLoggingEnabled;
55     std::unique_ptr<char[],free_deleter> m_tag;
56
57   public:
58     bool IsLoggingEnabled() const;
59     LogSystem();
60     virtual ~LogSystem();
61
62     /**
63      * Log debug message
64      */
65     void Debug(const char *message,
66                const char *filename,
67                int line,
68                const char *function,
69                const char *tag = NULL);
70
71     /**
72      * Log info message
73      */
74     void Info(const char *message,
75               const char *filename,
76               int line,
77               const char *function,
78               const char *tag = NULL);
79
80     /**
81      * Log warning message
82      */
83     void Warning(const char *message,
84                  const char *filename,
85                  int line,
86                  const char *function,
87                  const char *tag = NULL);
88
89     /**
90      * Log error message
91      */
92     void Error(const char *message,
93                const char *filename,
94                int line,
95                const char *function,
96                const char *tag = NULL);
97
98     /**
99      * Log pedantic message
100      */
101     void Pedantic(const char *message,
102                   const char *filename,
103                   int line,
104                   const char *function,
105                   const char *tag = NULL);
106
107     /**
108      * Set default's DLOG provider Tag
109      */
110     void SetTag(const char *tag);
111
112 };
113
114 /**
115  * Log system singleton
116  */
117 typedef Singleton<LogSystem> LogSystemSingleton;
118 }
119 } // namespace DPL
120
121 /**
122  * Logging API for C++
123  * This API print out messages to the main log buffer
124  */
125
126 #ifdef DPL_LOGS_ENABLED
127 #define DPL_MACRO_FOR_LOGGING(message, function) \
128 do {                                                                       \
129             std::ostringstream platformLog;                                \
130             platformLog << message;                                        \
131             DPL::Log::LogSystemSingleton::Instance().function(             \
132                 platformLog.str().c_str(),                                 \
133                 __FILE__, __LINE__, __FUNCTION__,                 \
134                 LOG_TAG);                         \
135 } while (0)
136 #else
137 #define DPL_MACRO_FOR_LOGGING(message, function) do { } while (0)
138 #endif
139
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)
145
146
147 /**
148  * Logging API for C
149  * This API print out messages to the system log buffer
150  */
151 #define INTERNAL_SECURE_LOG __extension__ SECURE_SLOG
152 #ifdef DPL_LOGS_ENABLED
153 #define WRT_LOG_(priority, ...) \
154 do { \
155     INTERNAL_SECURE_LOG(priority, LOG_TAG, __VA_ARGS__); \
156 } while(0)
157 #else
158 #define WRT_LOG_(priority, ...) do { } while (0)
159 #endif
160
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__)
165
166
167 /**
168  * Logging API for C
169  * This API print out messages to the system log buffer
170  */
171 #ifndef SECURE_SLOGD
172 #define SECURE_SLOGD(fmt, arg...) SLOGD(fmt,##arg)
173 #endif
174
175 #ifndef SECURE_SLOGW
176 #define SECURE_SLOGW(fmt, arg...) SLOGW(fmt,##arg)
177 #endif
178
179 #ifndef SECURE_SLOGE
180 #define SECURE_SLOGE(fmt, arg...) SLOGE(fmt,##arg)
181 #endif
182
183 #undef _D
184 #undef _W
185 #undef _E
186
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)
191 #else
192 #define _D(fmt, arg ...) do { } while (0)
193 #define _W(fmt, arg ...) do { } while (0)
194 #define _E(fmt, arg ...) do { } while (0)
195 #endif
196
197 #endif // DPL_LOG_H