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
23 #include <dpl/log/log.h>
24 #include <dpl/singleton_impl.h>
26 IMPLEMENT_SINGLETON(DPL::Log::LogSystem)
30 namespace // anonymous
32 const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS";
33 const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME =
34 "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
35 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
36 const char *DPL_LOG_OFF = "DPL_LOG_OFF";
37 } // namespace anonymous
39 bool LogSystem::IsLoggingEnabled() const
41 return m_isLoggingEnabled;
44 LogSystem::LogSystem() :
46 m_oldStyleProvider(NULL),
47 m_isLoggingEnabled(!getenv(DPL_LOG_OFF))
49 bool oldStyleLogs = false;
50 bool oldStyleDebugLogs = true;
51 bool oldStyleInfoLogs = true;
52 bool oldStyleWarningLogs = true;
53 bool oldStyleErrorLogs = true;
54 bool oldStylePedanticLogs = false;
56 // Check environment settings about pedantic logs
57 const char *value = getenv(OLD_STYLE_LOGS_ENV_NAME);
59 if (value != NULL && !strcmp(value, "1")) {
63 value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME);
65 if (value != NULL && !strcmp(value, "1")) {
66 oldStylePedanticLogs = true;
69 value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME);
72 size_t len = strlen(value);
75 if (value[0] == '0') {
76 oldStyleDebugLogs = false;
77 } else if (value[0] == '1') {
78 oldStyleDebugLogs = true;
83 if (value[1] == '0') {
84 oldStyleInfoLogs = false;
85 } else if (value[1] == '1') {
86 oldStyleInfoLogs = true;
91 if (value[2] == '0') {
92 oldStyleWarningLogs = false;
93 } else if (value[2] == '1') {
94 oldStyleWarningLogs = true;
99 if (value[3] == '0') {
100 oldStyleErrorLogs = false;
101 } else if (value[3] == '1') {
102 oldStyleErrorLogs = true;
107 // Setup default DLOG and old style logging
110 m_oldStyleProvider = new OldStyleLogProvider(oldStyleDebugLogs,
114 oldStylePedanticLogs);
115 AddProvider(m_oldStyleProvider);
118 m_dlogProvider = new DLOGLogProvider();
119 AddProvider(m_dlogProvider);
123 LogSystem::~LogSystem()
125 // Delete all providers
126 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
127 iterator != m_providers.end();
135 // And even default providers
136 m_dlogProvider = NULL;
137 m_oldStyleProvider = NULL;
140 void LogSystem::SetTag(const char* tag)
142 if (m_dlogProvider != NULL) {
143 m_dlogProvider->SetTag(tag);
147 void LogSystem::AddProvider(AbstractLogProvider *provider)
149 m_providers.push_back(provider);
152 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
154 m_providers.remove(provider);
157 void LogSystem::Debug(const char *message,
158 const char *filename,
160 const char *function)
162 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
163 iterator != m_providers.end();
166 (*iterator)->Debug(message, filename, line, function);
170 void LogSystem::Info(const char *message,
171 const char *filename,
173 const char *function)
175 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
176 iterator != m_providers.end();
179 (*iterator)->Info(message, filename, line, function);
183 void LogSystem::Warning(const char *message,
184 const char *filename,
186 const char *function)
188 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
189 iterator != m_providers.end();
192 (*iterator)->Warning(message, filename, line, function);
196 void LogSystem::Error(const char *message,
197 const char *filename,
199 const char *function)
201 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
202 iterator != m_providers.end();
205 (*iterator)->Error(message, filename, line, function);
209 void LogSystem::Pedantic(const char *message,
210 const char *filename,
212 const char *function)
214 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
215 iterator != m_providers.end();
218 (*iterator)->Pedantic(message, filename, line, function);