Set log level on startup from environment variable
This commit is contained in:
parent
6887a4a0ef
commit
ddc022466e
2 changed files with 25 additions and 0 deletions
|
|
@ -39,6 +39,12 @@ Daemon::Daemon()
|
||||||
.command(std::make_shared<cmds::SessionManager>())
|
.command(std::make_shared<cmds::SessionManager>())
|
||||||
.command(std::make_shared<cmds::Launch>())
|
.command(std::make_shared<cmds::Launch>())
|
||||||
.command(std::make_shared<cmds::ContainerManager>());
|
.command(std::make_shared<cmds::ContainerManager>());
|
||||||
|
|
||||||
|
Log().Init(anbox::Logger::Severity::kWarning);
|
||||||
|
|
||||||
|
const auto log_level = utils::get_env_value("ANBOX_LOG_LEVEL", "");
|
||||||
|
if (!log_level.empty())
|
||||||
|
Log().SetSeverity(log_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Daemon::Run(const std::vector<std::string> &arguments) try {
|
int Daemon::Run(const std::vector<std::string> &arguments) try {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,10 @@ struct BoostLogLogger : public anbox::Logger {
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetSeverity(const Severity& severity) override {
|
||||||
|
severity_ = severity;
|
||||||
|
}
|
||||||
|
|
||||||
void Log(Severity severity, const std::string& message, const boost::optional<Location>& loc) override {
|
void Log(Severity severity, const std::string& message, const boost::optional<Location>& loc) override {
|
||||||
if (!initialized_) Init();
|
if (!initialized_) Init();
|
||||||
|
|
||||||
|
|
@ -103,6 +107,21 @@ void SetInstance(const std::shared_ptr<anbox::Logger>& logger) {
|
||||||
}
|
}
|
||||||
namespace anbox {
|
namespace anbox {
|
||||||
|
|
||||||
|
void Logger::SetSeverity(const std::string& severity) {
|
||||||
|
if (severity == "trace")
|
||||||
|
SetSeverity(Severity::kTrace);
|
||||||
|
else if (severity == "debug")
|
||||||
|
SetSeverity(Severity::kDebug);
|
||||||
|
else if (severity == "info")
|
||||||
|
SetSeverity(Severity::kInfo);
|
||||||
|
else if (severity == "warning")
|
||||||
|
SetSeverity(Severity::kWarning);
|
||||||
|
else if (severity == "error")
|
||||||
|
SetSeverity(Severity::kError);
|
||||||
|
else if (severity == "fatal")
|
||||||
|
SetSeverity(Severity::kFatal);
|
||||||
|
}
|
||||||
|
|
||||||
void Logger::Trace(const std::string& message,
|
void Logger::Trace(const std::string& message,
|
||||||
const boost::optional<Location>& location) {
|
const boost::optional<Location>& location) {
|
||||||
Log(Severity::kTrace, message, location);
|
Log(Severity::kTrace, message, location);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue