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
22 #ifndef SECURITYMANAGER_LOG_H
23 #define SECURITYMANAGER_LOG_H
25 #include <dpl/singleton.h>
26 #include <dpl/noncopyable.h>
27 #include <dpl/log/abstract_log_provider.h>
31 namespace SecurityManager {
34 * SecurityManager log system
36 * To switch logs into old style, export
37 * DPL_USE_OLD_STYLE_LOGS before application start
43 typedef std::list<AbstractLogProvider *> AbstractLogProviderPtrList;
44 AbstractLogProviderPtrList m_providers;
46 bool m_isLoggingEnabled;
49 bool IsLoggingEnabled() const;
56 void Debug(const char *message,
59 const char *function);
64 void Info(const char *message,
67 const char *function);
72 void Warning(const char *message,
75 const char *function);
80 void Error(const char *message,
83 const char *function);
86 * Log pedantic message
88 void Pedantic(const char *message,
91 const char *function);
94 * Log pedantic message with secure macro
96 void SecureDebug(const char *message,
99 const char *function);
102 * Log info message with secure macro
104 void SecureInfo(const char *message,
105 const char *filename,
107 const char *function);
110 * Log warning message with secure macro
112 void SecureWarning(const char *message,
113 const char *filename,
115 const char *function);
118 * Log error message with secure macro
120 void SecureError(const char *message,
121 const char *filename,
123 const char *function);
126 * Set default's DLOG provider Tag
128 void SetTag(const char *tag);
131 * Add abstract provider to providers list
133 * @notice Ownership is transfered to LogSystem and deleted upon exit
135 void AddProvider(AbstractLogProvider *provider);
138 * Remove abstract provider from providers list
140 void RemoveProvider(AbstractLogProvider *provider);
144 * Replacement low overhead null logging class
151 template <typename T>
152 NullStream& operator<<(const T&)
159 * Log system singleton
161 typedef Singleton<LogSystem> LogSystemSingleton;
163 } // namespace SecurityManager
170 /* avoid warnings about unused variables */
171 #define DPL_MACRO_DUMMY_LOGGING(message, function) \
173 SecurityManager::Log::NullStream ns; \
177 #define DPL_MACRO_FOR_LOGGING(message, function) \
180 if (SecurityManager::Log::LogSystemSingleton::Instance().IsLoggingEnabled()) \
182 std::ostringstream platformLog; \
183 platformLog << message; \
184 SecurityManager::Log::LogSystemSingleton::Instance().function( \
185 platformLog.str().c_str(), \
186 __FILE__, __LINE__, __FUNCTION__); \
190 /* Errors must be always logged. */
191 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
192 #define LogSecureError(message) DPL_MACRO_FOR_LOGGING(message, SecureError)
194 #ifdef BUILD_TYPE_DEBUG
195 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
196 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
197 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
198 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)
199 #define LogSecureDebug(message) DPL_MACRO_FOR_LOGGING(message, SecureDebug)
200 #define LogSecureInfo(message) DPL_MACRO_FOR_LOGGING(message, SecureInfo)
201 #define LogSecureWarning(message) DPL_MACRO_FOR_LOGGING(message, SecureWarning)
203 #define LogDebug(message) DPL_MACRO_DUMMY_LOGGING(message, Debug)
204 #define LogInfo(message) DPL_MACRO_DUMMY_LOGGING(message, Info)
205 #define LogWarning(message) DPL_MACRO_DUMMY_LOGGING(message, Warning)
206 #define LogPedantic(message) DPL_MACRO_DUMMY_LOGGING(message, Pedantic)
207 #define LogSecureDebug(message) DPL_MACRO_DUMMY_LOGGING(message, SecureDebug)
208 #define LogSecureInfo(message) DPL_MACRO_DUMMY_LOGGING(message, SecureInfo)
209 #define LogSecureWarning(message) DPL_MACRO_DUMMY_LOGGING(message, SecureWarning)
210 #endif // BUILD_TYPE_DEBUG
212 #endif // SECURITYMANAGER_LOG_H