ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Log.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3
*
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
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
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.
15
*/
16
17
#include "
luci/Log.h
"
18
19
#include <
luci/UserSettings.h
>
20
21
#include <cassert>
22
#include <cstdlib>
23
#include <iostream>
24
25
// TODO Extract these lexical conversion routines as a library
26
namespace
27
{
28
34
template
<
typename
T> T safecast(
const
char
*,
const
T &);
35
36
template
<>
int
safecast<int>(
const
char
*s,
const
int
&value)
37
{
38
return
(s ==
nullptr
) ? value : std::stoi(s);
39
}
40
41
}
// namespace
42
43
//
44
// Logger
45
//
46
namespace
luci
47
{
48
49
Logger::Logger
(
hermes::Context
*ctx) {
activate
(ctx->
sources
(), ctx->
bus
()); }
50
Logger::~Logger
() {
deactivate
(); }
51
52
}
// namespace luci
53
54
//
55
// LoggerConfig
56
//
57
namespace
luci
58
{
59
60
LoggerConfig::LoggerConfig
()
61
{
62
auto
settings =
luci::UserSettings::settings
();
63
64
_show_warn = !settings->get(
luci::UserSettings::Key::MuteWarnings
);
65
66
// Turn on verbose logging if LUCI_LOG is set to some level
67
// VERBOSE(l, 1) will be visible with LUCI_LOG=2 and VERBOSE(l, 2) with LUCI_LOG=3 and so on
68
_show_verbose = safecast<int>(std::getenv(
"LUCI_LOG"
), 0);
69
}
70
71
void
LoggerConfig::configure
(
const
hermes::Source
*source,
hermes::Source::Setting
&setting)
const
72
{
73
// Let's ignore hermes::Sources if that is not a moco logger
74
if
(
auto
logger =
dynamic_cast<
const
Logger
*
>
(source))
75
{
76
configure
(logger, setting);
77
}
78
}
79
80
void
LoggerConfig::configure
(
const
Logger
*,
hermes::Source::Setting
&setting)
const
81
{
82
setting.
reject_all
();
83
setting.
filter
(
hermes::SeverityCategory::FATAL
).
accept_upto
(_show_verbose);
84
setting.
filter
(
hermes::SeverityCategory::ERROR
).
accept_upto
(_show_verbose);
85
if
(_show_warn)
86
{
87
setting.
filter
(
hermes::SeverityCategory::WARN
).
accept_upto
(_show_verbose);
88
}
89
setting.
filter
(
hermes::SeverityCategory::INFO
).
accept_upto
(_show_verbose);
90
setting.
filter
(
hermes::SeverityCategory::VERBOSE
).
accept_upto
(_show_verbose);
91
}
92
93
}
// namespace luci
UserSettings.h
hermes::Context
Logging controller.
Definition
Context.h:40
hermes::Context::sources
Source::Registry * sources(void)
Definition
Context.h:55
hermes::Context::bus
MessageBus * bus(void)
Definition
Context.h:48
hermes::Filter::accept_upto
void accept_upto(uint16_t lv)
Definition
SourceSetting.h:36
hermes::Source
Message Source.
Definition
Source.h:35
hermes::Source::deactivate
void deactivate(void)
Definition
Source.cpp:49
hermes::Source::activate
void activate(Registry *, MessageBus *)
Definition
Source.cpp:37
hermes::SourceSetting
Definition
SourceSetting.h:59
hermes::SourceSetting::filter
Filter filter(const SeverityCategory &cat)
Definition
SourceSetting.h:86
hermes::SourceSetting::reject_all
void reject_all(void)
Definition
SourceSetting.h:68
luci::LoggerConfig::configure
void configure(const hermes::Source *, hermes::Source::Setting &) const final
Definition
Log.cpp:71
luci::LoggerConfig::LoggerConfig
LoggerConfig()
Definition
Log.cpp:60
luci::Logger
Logger Implementation.
Definition
Log.h:29
luci::Logger::~Logger
~Logger()
Definition
Log.cpp:50
luci::Logger::Logger
Logger(hermes::Context *ctx)
Definition
Log.cpp:49
Log.h
hermes::FATAL
@ FATAL
Definition
Severity.h:33
hermes::ERROR
@ ERROR
Definition
Severity.h:34
hermes::VERBOSE
@ VERBOSE
Definition
Severity.h:37
hermes::INFO
@ INFO
Definition
Severity.h:36
hermes::WARN
@ WARN
Definition
Severity.h:35
luci
Definition
DepthwiseConv2D.h:24
luci::UserSettings::settings
static UserSettings * settings()
Definition
UserSettings.cpp:83
luci::UserSettings::MuteWarnings
@ MuteWarnings
Definition
UserSettings.h:33
compiler
luci
log
src
Log.cpp
Generated by
1.9.8