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)
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 = "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
36 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
37 const char *DPL_LOG_OFF = "DPL_LOG_OFF";
38 } // namespace anonymous
41 bool LogSystem::IsLoggingEnabled() const
43 return m_isLoggingEnabled;
46 LogSystem::LogSystem()
47 : m_dlogProvider(NULL),
48 m_oldStyleProvider(NULL),
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 != NULL && !strcmp(value, "1"))
64 value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME);
66 if (value != NULL && !strcmp(value, "1"))
67 oldStylePedanticLogs = true;
69 value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME);
73 size_t len = strlen(value);
78 oldStyleDebugLogs = false;
79 else if (value[0] == '1')
80 oldStyleDebugLogs = true;
86 oldStyleInfoLogs = false;
87 else if (value[1] == '1')
88 oldStyleInfoLogs = true;
94 oldStyleWarningLogs = false;
95 else if (value[2] == '1')
96 oldStyleWarningLogs = true;
102 oldStyleErrorLogs = false;
103 else if (value[3] == '1')
104 oldStyleErrorLogs = true;
108 // Setup default DLOG and old style logging
112 m_oldStyleProvider = new OldStyleLogProvider(oldStyleDebugLogs, oldStyleInfoLogs, oldStyleWarningLogs, oldStyleErrorLogs, oldStylePedanticLogs);
113 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(); iterator != m_providers.end(); ++iterator)
131 // And even default providers
132 m_dlogProvider = NULL;
133 m_oldStyleProvider = NULL;
136 void LogSystem::SetTag(const char* tag)
138 if (m_dlogProvider != NULL)
139 m_dlogProvider->SetTag(tag);
142 void LogSystem::AddProvider(AbstractLogProvider *provider)
144 m_providers.push_back(provider);
147 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
149 m_providers.remove(provider);
152 void LogSystem::Debug(const char *message, const char *filename, int line, const char *function)
154 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); iterator != m_providers.end(); ++iterator)
155 (*iterator)->Debug(message, filename, line, function);
158 void LogSystem::Info(const char *message, const char *filename, int line, const char *function)
160 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); iterator != m_providers.end(); ++iterator)
161 (*iterator)->Info(message, filename, line, function);
164 void LogSystem::Warning(const char *message, const char *filename, int line, const char *function)
166 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); iterator != m_providers.end(); ++iterator)
167 (*iterator)->Warning(message, filename, line, function);
170 void LogSystem::Error(const char *message, const char *filename, int line, const char *function)
172 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); iterator != m_providers.end(); ++iterator)
173 (*iterator)->Error(message, filename, line, function);
176 void LogSystem::Pedantic(const char *message, const char *filename, int line, const char *function)
178 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); iterator != m_providers.end(); ++iterator)
179 (*iterator)->Pedantic(message, filename, line, function);