2 * Copyright (c) 2000 - 2014 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
17 * @file journal_log_provider.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include <dpl/log/journal_log_provider.h>
23 #include <systemd/sd-journal.h>
31 std::map<AbstractLogProvider::LogLevel, int> journalLevel = {
32 { AbstractLogProvider::LogLevel::Error, LOG_ERR },
33 { AbstractLogProvider::LogLevel::Warning, LOG_WARNING },
34 { AbstractLogProvider::LogLevel::Info, LOG_INFO },
35 { AbstractLogProvider::LogLevel::Debug, LOG_DEBUG },
36 { AbstractLogProvider::LogLevel::Pedantic, LOG_DEBUG }
39 } // namespace anonymous
41 JournalLogProvider::JournalLogProvider()
44 JournalLogProvider::~JournalLogProvider()
47 void JournalLogProvider::Log(AbstractLogProvider::LogLevel level,
51 const char *function) const
54 sd_journal_send("PRIORITY=%d", journalLevel.at(level),
55 "CODE_FILE=%s", fileName,
56 "CODE_FUNC=%s", function,
58 // add file, line & function info to log message
59 "MESSAGE=[%s:%d] %s(): %s", fileName, line, function, message,
61 } catch (const std::out_of_range&) {
63 "PRIORITY=%d", LOG_ERR,
64 "CODE_FILE=%s", fileName,
65 "CODE_FUNC=%s", function,
67 // add file, line & function info to log message
68 "MESSAGE=[%s:%d] %s(): Unsupported log level %d", fileName, line, function, level,
74 } /* namespace VcoreDPL */