提交 ddc02246 编写于 作者: S Simon Fels

Set log level on startup from environment variable

上级 6887a4a0
......@@ -39,6 +39,12 @@ Daemon::Daemon()
.command(std::make_shared<cmds::SessionManager>())
.command(std::make_shared<cmds::Launch>())
.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 {
......
......@@ -60,6 +60,10 @@ struct BoostLogLogger : public anbox::Logger {
initialized_ = true;
}
void SetSeverity(const Severity& severity) override {
severity_ = severity;
}
void Log(Severity severity, const std::string& message, const boost::optional<Location>& loc) override {
if (!initialized_) Init();
......@@ -103,6 +107,21 @@ void SetInstance(const std::shared_ptr<anbox::Logger>& logger) {
}
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,
const boost::optional<Location>& location) {
Log(Severity::kTrace, message, location);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册