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>
30 #include <dpl/read_write_mutex.h>
41 * To switch logs into old style, export
42 * DPL_USE_OLD_STYLE_LOGS before application start
48 ReadWriteMutex m_spinLock;
50 typedef std::list<AbstractLogProvider *> AbstractLogProviderPtrList;
51 AbstractLogProviderPtrList m_providers;
53 DLOGLogProvider *m_dlogProvider;
54 OldStyleLogProvider *m_oldStyleProvider;
56 bool m_isLoggingEnabled;
59 bool IsLoggingEnabled() const;
66 void Debug(const char *message, const char *filename, int line, const char *function);
71 void Info(const char *message, const char *filename, int line, const char *function);
76 void Warning(const char *message, const char *filename, int line, const char *function);
81 void Error(const char *message, const char *filename, int line, const char *function);
84 * Log pedantic message
86 void Pedantic(const char *message, const char *filename, int line, const char *function);
89 * Set default's DLOG provider Tag
91 void SetTag(const char *tag);
94 * Add abstract provider to providers list
96 * @notice Ownership is transfered to LogSystem and deleted upon exit
98 void AddProvider(AbstractLogProvider *provider);
101 * Remove abstract provider from providers list
103 void RemoveProvider(AbstractLogProvider *provider);
107 * Replacement low overhead null logging class
113 template <typename T>
114 NullStream& operator<<(const T&) { return *this; }
118 * Log system singleton
120 typedef Singleton<LogSystem> LogSystemSingleton;
130 #ifdef DPL_LOGS_ENABLED
131 #define DPL_MACRO_FOR_LOGGING(message, function) \
134 if (DPL::Log::LogSystemSingleton::Instance().IsLoggingEnabled()) \
136 std::ostringstream platformLog; \
137 platformLog << message; \
138 DPL::Log::LogSystemSingleton::Instance().function( \
139 platformLog.str().c_str(), \
140 __FILE__, __LINE__, __FUNCTION__); \
144 /* avoid warnings about unused variables */
145 #define DPL_MACRO_FOR_LOGGING(message, function) \
147 DPL::Log::NullStream ns; \
153 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
154 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
155 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
156 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
157 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)