Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dlt application and context properties to commonapi.ini #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
3 changes: 2 additions & 1 deletion include/CommonAPI/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Logger {
}

static void init(bool _useConsole, const std::string &_fileName,
bool _useDlt, const std::string& _level);
bool _useDlt, const std::string& _level,
const std::string& _logApplication, const std::string& _logContext);

private:
class LoggerImpl;
Expand Down
12 changes: 7 additions & 5 deletions src/CommonAPI/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Logger::LoggerImpl {
}

void init(bool _useConsole, const std::string &_fileName, bool _useDlt,
const std::string& _level) {
const std::string& _level,
const std::string& _logApplication, const std::string& _logContext) {
useConsole_ = _useConsole;
maximumLogLevel_ = stringAsLevel(_level);
useDlt_ = _useDlt;
Expand All @@ -45,13 +46,13 @@ class Logger::LoggerImpl {
}
#ifdef USE_DLT
if (useDlt_) {
std::string app = Runtime::getProperty("LogApplication");
std::string app = _logApplication;
if (!app.empty()) {
ownAppID_ = true;
DLT_REGISTER_APP(app.c_str(), "CommonAPI Application");
}

std::string context = Runtime::getProperty("LogContext");
std::string context = _logContext;
if (context == "")
context = "CAPI";
DLT_REGISTER_CONTEXT(dlt_, context.c_str(), "CAPI");
Expand Down Expand Up @@ -183,8 +184,9 @@ Logger::Logger() = default;
Logger::~Logger() = default;

void Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt,
const std::string& _level) {
loggerImpl_->init(_useConsole, _fileName, _useDlt, _level);
const std::string& _level,
const std::string& _logApplication, const std::string& _logContext) {
loggerImpl_->init(_useConsole, _fileName, _useDlt, _level, _logApplication, _logContext);
}

bool Logger::isLogged(Level _level) {
Expand Down
8 changes: 7 additions & 1 deletion src/CommonAPI/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Runtime::readConfiguration() {
std::string itsFile;
std::string itsDlt("false");
std::string itsLevel("info");
std::string itsLogApplication;
std::string itsLogContext;

std::shared_ptr<IniFileReader::Section> section
= reader.getSection("logging");
Expand All @@ -210,12 +212,16 @@ Runtime::readConfiguration() {
itsFile = section->getValue("file");
itsDlt = section->getValue("dlt");
itsLevel = section->getValue("level");
itsLogApplication = section->getValue("logApplication");
itsLogContext = section->getValue("logContext");
}

Logger::init((itsConsole == "true"),
itsFile,
(itsDlt == "true"),
itsLevel);
itsLevel,
itsLogApplication,
itsLogContext);

section = reader.getSection("default");
if (section) {
Expand Down