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/log/log.h>
26 #include <dpl/singleton_impl.h>
28 IMPLEMENT_SINGLETON(DPL::Log::LogSystem)
32 namespace // anonymous
34 const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS";
35 const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME =
36 "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
37 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
38 const char *DPL_LOG_OFF = "DPL_LOG_OFF";
39 } // namespace anonymous
41 bool LogSystem::IsLoggingEnabled() const
43 return m_isLoggingEnabled;
46 LogSystem::LogSystem() :
47 m_dlogProvider(nullptr),
48 m_oldStyleProvider(nullptr),
49 m_isLoggingEnabled(!getenv(DPL_LOG_OFF))
51 bool oldStyleLogs = false;
52 bool oldStyleDebugLogs = true;
53 bool oldStyleInfoLogs = true;
54 bool oldStyleWarningLogs = true;
55 bool oldStyleErrorLogs = true;
56 bool oldStylePedanticLogs = false;
58 // Check environment settings about pedantic logs
59 const char *value = getenv(OLD_STYLE_LOGS_ENV_NAME);
61 if (value != nullptr && !strcmp(value, "1")) {
65 value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME);
67 if (value != nullptr && !strcmp(value, "1")) {
68 oldStylePedanticLogs = true;
71 value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME);
73 if (value != nullptr) {
74 size_t len = strlen(value);
77 if (value[0] == '0') {
78 oldStyleDebugLogs = false;
79 } else if (value[0] == '1') {
80 oldStyleDebugLogs = true;
85 if (value[1] == '0') {
86 oldStyleInfoLogs = false;
87 } else if (value[1] == '1') {
88 oldStyleInfoLogs = true;
93 if (value[2] == '0') {
94 oldStyleWarningLogs = false;
95 } else if (value[2] == '1') {
96 oldStyleWarningLogs = true;
101 if (value[3] == '0') {
102 oldStyleErrorLogs = false;
103 } else if (value[3] == '1') {
104 oldStyleErrorLogs = true;
109 // Setup default DLOG and old style logging
112 m_oldStyleProvider = new OldStyleLogProvider(oldStyleDebugLogs,
116 oldStylePedanticLogs);
117 AddProvider(m_oldStyleProvider);
120 m_dlogProvider = new DLOGLogProvider();
121 AddProvider(m_dlogProvider);
125 LogSystem::~LogSystem()
127 // Delete all providers
128 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
129 iterator != m_providers.end();
137 // And even default providers
138 m_dlogProvider = nullptr;
139 m_oldStyleProvider = nullptr;
142 void LogSystem::SetTag(const char* tag)
144 if (m_dlogProvider != nullptr) {
145 m_dlogProvider->SetTag(tag);
149 void LogSystem::AddProvider(AbstractLogProvider *provider)
151 m_providers.push_back(provider);
154 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
156 m_providers.remove(provider);
159 void LogSystem::Debug(const char *message,
160 const char *filename,
162 const char *function)
164 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
165 iterator != m_providers.end();
168 (*iterator)->Debug(message, filename, line, function);
172 void LogSystem::Info(const char *message,
173 const char *filename,
175 const char *function)
177 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
178 iterator != m_providers.end();
181 (*iterator)->Info(message, filename, line, function);
185 void LogSystem::Warning(const char *message,
186 const char *filename,
188 const char *function)
190 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
191 iterator != m_providers.end();
194 (*iterator)->Warning(message, filename, line, function);
198 void LogSystem::Error(const char *message,
199 const char *filename,
201 const char *function)
203 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
204 iterator != m_providers.end();
207 (*iterator)->Error(message, filename, line, function);
211 void LogSystem::Pedantic(const char *message,
212 const char *filename,
214 const char *function)
216 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
217 iterator != m_providers.end();
220 (*iterator)->Pedantic(message, filename, line, function);