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
27 #include <unordered_map>
30 #include <dpl/singleton.h>
31 #include <dpl/noncopyable.h>
33 #include <dpl/log/abstract_log_provider.h>
40 * To switch logs into old style, export
41 * DPL_USE_OLD_STYLE_LOGS before application start
43 class LogSystem : private Noncopyable
49 AbstractLogProvider::LogLevel GetLogLevel() const { return m_level; }
51 void Log(AbstractLogProvider::LogLevel level,
55 const char *function) const;
59 * Set default's DLOG provider Tag
61 void SetTag(const char *tag);
64 * Add abstract provider to providers list
66 * @notice Ownership is transfered to LogSystem and deleted upon exit
68 void AddProvider(AbstractLogProvider *provider);
71 * Remove abstract provider from providers list
73 void RemoveProvider(AbstractLogProvider *provider);
76 * Selects given provider by name (overwrites environment setting)
78 * Throws std::out_of_range exception if not found.
80 void SelectProvider(const std::string& name);
83 * Sets log level (overwrites environment settings)
85 void SetLogLevel(const char* level);
88 void RemoveProviders();
90 typedef std::list<AbstractLogProvider *> AbstractLogProviderPtrList;
91 AbstractLogProviderPtrList m_providers;
92 AbstractLogProvider::LogLevel m_level;
94 typedef AbstractLogProvider *(*ProviderFn)();
96 * It cannot be global as it is used in library constructor and we can't be sure which
97 * constructor is called first: library's or new_provider's.
99 std::unordered_map<std::string, ProviderFn> m_providerCtor;
103 * Replacement low overhead null logging class
110 template <typename T>
111 NullStream& operator<<(const T&)
118 * Log system singleton
120 typedef Singleton<LogSystem> LogSystemSingleton;
122 } // namespace VcoreDPL
125 /* avoid warnings about unused variables */
126 #define DPL_MACRO_DUMMY_LOGGING(message, level) \
128 VcoreDPL::Log::NullStream ns; \
132 #define DPL_MACRO_FOR_LOGGING(message, level) \
135 if (level > VcoreDPL::Log::AbstractLogProvider::LogLevel::None && \
136 VcoreDPL::Log::LogSystemSingleton::Instance().GetLogLevel() >= level) \
138 std::ostringstream platformLog; \
139 platformLog << message; \
140 VcoreDPL::Log::LogSystemSingleton::Instance().Log(level, \
141 platformLog.str().c_str(), \
148 #define LogError(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Error)
150 #ifdef BUILD_TYPE_DEBUG
151 #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug)
152 #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Info)
153 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Warning)
154 #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic)
156 #define LogDebug(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug)
157 #define LogInfo(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Info)
158 #define LogWarning(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Warning)
159 #define LogPedantic(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic)
160 #endif // BUILD_TYPE_DEBUG