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
25 #include <dpl/singleton.h>
26 #include <dpl/noncopyable.h>
27 #include <dpl/log/abstract_log_provider.h>
28 #include <dpl/log/dlog_log_provider.h>
29 #include <dpl/log/old_style_log_provider.h>
38 * To switch logs into old style, export
39 * DPL_USE_OLD_STYLE_LOGS before application start
45 typedef std::list<AbstractLogProvider *> AbstractLogProviderPtrList;
46 AbstractLogProviderPtrList m_providers;
48 DLOGLogProvider *m_dlogProvider;
49 OldStyleLogProvider *m_oldStyleProvider;
51 bool m_isLoggingEnabled;
54 bool IsLoggingEnabled() const;
61 void Debug(const char *message,
64 const char *function);
69 void Info(const char *message,
72 const char *function);
77 void Warning(const char *message,
80 const char *function);
85 void Error(const char *message,
88 const char *function);
91 * Log pedantic message
93 void Pedantic(const char *message,
96 const char *function);
99 * Set default's DLOG provider Tag
101 void SetTag(const char *tag);
104 * Add abstract provider to providers list
106 * @notice Ownership is transfered to LogSystem and deleted upon exit
108 void AddProvider(AbstractLogProvider *provider);
111 * Remove abstract provider from providers list
113 void RemoveProvider(AbstractLogProvider *provider);
117 * Replacement low overhead null logging class
124 template <typename T>
125 NullStream& operator<<(const T&)
132 * Log system singleton
134 typedef Singleton<LogSystem> LogSystemSingleton;
143 #ifdef DPL_LOGS_ENABLED
144 #define DPL_MACRO_FOR_LOGGING(message, function) \
147 if (DPL::Log::LogSystemSingleton::Instance().IsLoggingEnabled()) \
149 std::ostringstream platformLog; \
150 platformLog << message; \
151 DPL::Log::LogSystemSingleton::Instance().function( \
152 platformLog.str().c_str(), \
153 __FILE__, __LINE__, __FUNCTION__); \
157 /* avoid warnings about unused variables */
158 #define DPL_MACRO_FOR_LOGGING(message, function) \
160 DPL::Log::NullStream ns; \
165 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
166 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
167 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
168 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
169 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)