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
27 #include <dpl/singleton_impl.h>
28 #include <dpl/log/old_style_log_provider.h>
29 #include <dpl/log/dlog_log_provider.h>
30 #include <dpl/log/journal_log_provider.h>
32 #include <dpl/log/log.h>
34 IMPLEMENT_SINGLETON(VcoreDPL::Log::LogSystem)
38 namespace // anonymous
40 const char *const CERTSVC_LOG_LEVEL = "CERTSVC_LOG_LEVEL";
41 const char *const CERTSVC_LOG_PROVIDER = "CERTSVC_LOG_PROVIDER";
43 const char *const CONSOLE = "CONSOLE";
44 const char *const DLOG = "DLOG";
45 const char *const JOURNALD = "JOURNALD";
46 } // namespace anonymous
48 LogSystem::LogSystem()
50 #ifdef BUILD_TYPE_DEBUG
51 { CONSOLE, []{ return static_cast<AbstractLogProvider *>(new OldStyleLogProvider()); }},
53 { DLOG, []{ return static_cast<AbstractLogProvider *>(new DLOGLogProvider()); }},
54 { JOURNALD, []{ return static_cast<AbstractLogProvider *>(new JournalLogProvider()); }}
57 SetLogLevel(getenv(CERTSVC_LOG_LEVEL));
59 AbstractLogProvider *prv = NULL;
61 prv = m_providerCtor.at(getenv(CERTSVC_LOG_PROVIDER))();
62 } catch (const std::exception &) {
63 prv = m_providerCtor[JOURNALD]();
69 LogSystem::~LogSystem()
74 void LogSystem::SetTag(const char* tag)
76 for (auto &it : m_providers)
80 void LogSystem::AddProvider(AbstractLogProvider *provider)
82 m_providers.push_back(provider);
85 void LogSystem::RemoveProvider(AbstractLogProvider *provider)
87 m_providers.remove(provider);
90 void LogSystem::SelectProvider(const std::string &name)
92 ProviderFn& prv = m_providerCtor.at(name);
98 void LogSystem::SetLogLevel(const char *level)
101 m_level = static_cast<AbstractLogProvider::LogLevel>(std::stoi(level));
102 } catch(const std::exception&) {
103 m_level = AbstractLogProvider::LogLevel::Debug;
106 if (m_level < AbstractLogProvider::LogLevel::None)
107 m_level = AbstractLogProvider::LogLevel::None;
108 else if (m_level > AbstractLogProvider::LogLevel::Pedantic)
109 m_level = AbstractLogProvider::LogLevel::Pedantic;
111 #ifndef BUILD_TYPE_DEBUG
112 if (m_level > AbstractLogProvider::LogLevel::Error)
113 m_level = AbstractLogProvider::LogLevel::Error;
114 #endif // BUILD_TYPE_DEBUG
117 void LogSystem::Log(AbstractLogProvider::LogLevel level,
119 const char *filename,
121 const char *function) const
123 for (const auto &it : m_providers)
124 it->Log(level, message, filename, line, function);
127 void LogSystem::RemoveProviders()
129 for (auto &it : m_providers)
135 } // namespace VcoreDPL