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>
27 #include <dpl/log/dlog_log_provider.h>
28 #include <dpl/log/old_style_log_provider.h>
30 IMPLEMENT_SINGLETON(SecurityManager::Log::LogSystem)
32 namespace SecurityManager {
34 namespace // anonymous
36 #ifdef BUILD_TYPE_DEBUG
37 const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS";
38 const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME =
39 "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
40 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
41 #endif // BUILD_TYPE_DEBUG
42 const char *SECURITY_MANAGER_LOG_OFF = "DPL_LOG_OFF";
43 } // namespace anonymous
45 bool LogSystem::IsLoggingEnabled() const
47 return m_isLoggingEnabled;
50 LogSystem::LogSystem() :
51 m_isLoggingEnabled(!getenv(SECURITY_MANAGER_LOG_OFF))
53 #ifdef BUILD_TYPE_DEBUG
54 bool oldStyleLogs = false;
55 bool oldStyleDebugLogs = true;
56 bool oldStyleInfoLogs = true;
57 bool oldStyleWarningLogs = true;
58 bool oldStyleErrorLogs = true;
59 bool oldStylePedanticLogs = false;
61 // Check environment settings about pedantic logs
62 const char *value = getenv(OLD_STYLE_LOGS_ENV_NAME);
64 if (value != NULL && !strcmp(value, "1")) {
68 value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME);
70 if (value != NULL && !strcmp(value, "1")) {
71 oldStylePedanticLogs = true;
74 value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME);
77 size_t len = strlen(value);
80 if (value[0] == '0') {
81 oldStyleDebugLogs = false;
82 } else if (value[0] == '1') {
83 oldStyleDebugLogs = true;
88 if (value[1] == '0') {
89 oldStyleInfoLogs = false;
90 } else if (value[1] == '1') {
91 oldStyleInfoLogs = true;
96 if (value[2] == '0') {
97 oldStyleWarningLogs = false;
98 } else if (value[2] == '1') {
99 oldStyleWarningLogs = true;
104 if (value[3] == '0') {
105 oldStyleErrorLogs = false;
106 } else if (value[3] == '1') {
107 oldStyleErrorLogs = true;
112 // Setup default DLOG and old style logging
115 AddProvider(new OldStyleLogProvider(oldStyleDebugLogs,
119 oldStylePedanticLogs));
122 AddProvider(new DLOGLogProvider());
124 #else // BUILD_TYPE_DEBUG
125 AddProvider(new DLOGLogProvider());
126 #endif // BUILD_TYPE_DEBUG
129 LogSystem::~LogSystem()
131 // Delete all providers
132 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
133 iterator != m_providers.end();
142 void LogSystem::SetTag(const char* tag)
144 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
145 iterator != m_providers.end();
148 (*iterator)->SetTag(tag);
152 void LogSystem::AddProvider(AbstractLogProvider *provider)
154 m_providers.push_back(provider);
157 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
159 m_providers.remove(provider);
162 void LogSystem::Debug(const char *message,
163 const char *filename,
165 const char *function)
167 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
168 iterator != m_providers.end();
171 (*iterator)->Debug(message, filename, line, function);
175 void LogSystem::Info(const char *message,
176 const char *filename,
178 const char *function)
180 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
181 iterator != m_providers.end();
184 (*iterator)->Info(message, filename, line, function);
188 void LogSystem::Warning(const char *message,
189 const char *filename,
191 const char *function)
193 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
194 iterator != m_providers.end();
197 (*iterator)->Warning(message, filename, line, function);
201 void LogSystem::Error(const char *message,
202 const char *filename,
204 const char *function)
206 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
207 iterator != m_providers.end();
210 (*iterator)->Error(message, filename, line, function);
214 void LogSystem::Pedantic(const char *message,
215 const char *filename,
217 const char *function)
219 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
220 iterator != m_providers.end();
223 (*iterator)->Pedantic(message, filename, line, function);
227 void LogSystem::SecureInfo(const char *message,
228 const char *filename,
230 const char *function)
232 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
233 iterator != m_providers.end();
236 (*iterator)->SecureInfo(message, filename, line, function);
240 void LogSystem::SecureDebug(const char *message,
241 const char *filename,
243 const char *function)
245 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
246 iterator != m_providers.end();
249 (*iterator)->SecureDebug(message, filename, line, function);
253 void LogSystem::SecureError(const char *message,
254 const char *filename,
256 const char *function)
258 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
259 iterator != m_providers.end();
262 (*iterator)->SecureError(message, filename, line, function);
266 void LogSystem::SecureWarning(const char *message,
267 const char *filename,
269 const char *function)
271 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
272 iterator != m_providers.end();
275 (*iterator)->SecureWarning(message, filename, line, function);
280 } // namespace SecurityManager