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>
29 #include <dpl/log/audit-smack-log.h>
31 IMPLEMENT_SINGLETON(SecurityManager::Log::LogSystem)
33 namespace SecurityManager {
35 namespace // anonymous
37 #ifdef BUILD_TYPE_DEBUG
38 const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS";
39 const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME =
40 "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
41 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
42 #endif // BUILD_TYPE_DEBUG
43 const char *SECURITY_MANAGER_LOG_OFF = "DPL_LOG_OFF";
44 } // namespace anonymous
46 bool LogSystem::IsLoggingEnabled() const
48 return m_isLoggingEnabled;
51 LogSystem::LogSystem() :
52 m_isLoggingEnabled(!getenv(SECURITY_MANAGER_LOG_OFF))
54 #ifdef BUILD_TYPE_DEBUG
55 bool oldStyleLogs = false;
56 bool oldStyleDebugLogs = true;
57 bool oldStyleInfoLogs = true;
58 bool oldStyleWarningLogs = true;
59 bool oldStyleErrorLogs = true;
60 bool oldStylePedanticLogs = false;
62 // Check environment settings about pedantic logs
63 const char *value = getenv(OLD_STYLE_LOGS_ENV_NAME);
65 if (value != NULL && !strcmp(value, "1")) {
69 value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME);
71 if (value != NULL && !strcmp(value, "1")) {
72 oldStylePedanticLogs = true;
75 value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME);
78 size_t len = strlen(value);
81 if (value[0] == '0') {
82 oldStyleDebugLogs = false;
83 } else if (value[0] == '1') {
84 oldStyleDebugLogs = true;
89 if (value[1] == '0') {
90 oldStyleInfoLogs = false;
91 } else if (value[1] == '1') {
92 oldStyleInfoLogs = true;
97 if (value[2] == '0') {
98 oldStyleWarningLogs = false;
99 } else if (value[2] == '1') {
100 oldStyleWarningLogs = true;
105 if (value[3] == '0') {
106 oldStyleErrorLogs = false;
107 } else if (value[3] == '1') {
108 oldStyleErrorLogs = true;
113 // Setup default DLOG and old style logging
116 AddProvider(new OldStyleLogProvider(oldStyleDebugLogs,
120 oldStylePedanticLogs));
123 AddProvider(new DLOGLogProvider());
125 #else // BUILD_TYPE_DEBUG
126 AddProvider(new DLOGLogProvider());
127 #endif // BUILD_TYPE_DEBUG
130 LogSystem::~LogSystem()
132 // Delete all providers
133 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
134 iterator != m_providers.end();
143 void LogSystem::SetTag(const char* tag)
145 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
146 iterator != m_providers.end();
149 (*iterator)->SetTag(tag);
153 void LogSystem::AddProvider(AbstractLogProvider *provider)
155 m_providers.push_back(provider);
158 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
160 m_providers.remove(provider);
163 void LogSystem::Debug(const char *message,
164 const char *filename,
166 const char *function)
168 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
169 iterator != m_providers.end();
172 (*iterator)->Debug(message, filename, line, function);
176 void LogSystem::Info(const char *message,
177 const char *filename,
179 const char *function)
181 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
182 iterator != m_providers.end();
185 (*iterator)->Info(message, filename, line, function);
189 void LogSystem::Warning(const char *message,
190 const char *filename,
192 const char *function)
194 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
195 iterator != m_providers.end();
198 (*iterator)->Warning(message, filename, line, function);
202 void LogSystem::Error(const char *message,
203 const char *filename,
205 const char *function)
207 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
208 iterator != m_providers.end();
211 (*iterator)->Error(message, filename, line, function);
215 void LogSystem::Pedantic(const char *message,
216 const char *filename,
218 const char *function)
220 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
221 iterator != m_providers.end();
224 (*iterator)->Pedantic(message, filename, line, function);
228 void LogSystem::SecureInfo(const char *message,
229 const char *filename,
231 const char *function)
233 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
234 iterator != m_providers.end();
237 (*iterator)->SecureInfo(message, filename, line, function);
241 void LogSystem::SecureDebug(const char *message,
242 const char *filename,
244 const char *function)
246 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
247 iterator != m_providers.end();
250 (*iterator)->SecureDebug(message, filename, line, function);
254 void LogSystem::SecureError(const char *message,
255 const char *filename,
257 const char *function)
259 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
260 iterator != m_providers.end();
263 (*iterator)->SecureError(message, filename, line, function);
267 void LogSystem::SecureWarning(const char *message,
268 const char *filename,
270 const char *function)
272 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
273 iterator != m_providers.end();
276 (*iterator)->SecureWarning(message, filename, line, function);
280 void LogSystem::SmackAudit(const char *message,
281 const char *fileName,
283 const char *function)
285 for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
286 iterator != m_providers.end();
289 (*iterator)->SmackAudit(message, fileName, line, function);
294 } // namespace SecurityManager