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>
40 * To switch logs into old style, export
41 * DPL_USE_OLD_STYLE_LOGS before application start
47 typedef std::list<AbstractLogProvider *> AbstractLogProviderPtrList;
48 AbstractLogProviderPtrList m_providers;
50 DLOGLogProvider *m_dlogProvider;
51 OldStyleLogProvider *m_oldStyleProvider;
53 bool m_isLoggingEnabled;
56 bool IsLoggingEnabled() const;
63 void Debug(const char *message, const char *filename, int line, const char *function);
68 void Info(const char *message, const char *filename, int line, const char *function);
73 void Warning(const char *message, const char *filename, int line, const char *function);
78 void Error(const char *message, const char *filename, int line, const char *function);
81 * Log pedantic message
83 void Pedantic(const char *message, const char *filename, int line, const char *function);
86 * Set default's DLOG provider Tag
88 void SetTag(const char *tag);
91 * Add abstract provider to providers list
93 * @notice Ownership is transfered to LogSystem and deleted upon exit
95 void AddProvider(AbstractLogProvider *provider);
98 * Remove abstract provider from providers list
100 void RemoveProvider(AbstractLogProvider *provider);
104 * Replacement low overhead null logging class
110 template <typename T>
111 NullStream& operator<<(const T&) { return *this; }
115 * Log system singleton
117 typedef Singleton<LogSystem> LogSystemSingleton;
127 #ifdef DPL_LOGS_ENABLED
128 #define DPL_MACRO_FOR_LOGGING(message, function) \
131 if (DPL::Log::LogSystemSingleton::Instance().IsLoggingEnabled()) \
133 std::ostringstream platformLog; \
134 platformLog << message; \
135 DPL::Log::LogSystemSingleton::Instance().function( \
136 platformLog.str().c_str(), \
137 __FILE__, __LINE__, __FUNCTION__); \
141 /* avoid warnings about unused variables */
142 #define DPL_MACRO_FOR_LOGGING(message, function) \
144 DPL::Log::NullStream ns; \
150 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
151 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
152 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
153 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
154 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)