ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Log.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 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 "
Log.h
"
18
19
#include <
hermes/ConsoleReporter.h
>
20
21
#include <cstdlib>
22
#include <iostream>
23
24
// TODO Extract these lexical conversion routines as a library
25
namespace
26
{
27
33
template
<
typename
T> T safecast(
const
char
*,
const
T &);
34
35
template
<>
bool
safecast<bool>(
const
char
*s,
const
bool
&value)
36
{
37
return
(s ==
nullptr
) ? value : (std::stoi(s) != 0);
38
}
39
40
}
// namespace
41
42
namespace
exo
43
{
44
45
//
46
// Logger
47
//
48
Logger::Logger
(
hermes::Context
*ctx) {
activate
(ctx->
sources
(), ctx->
bus
()); }
49
Logger::~Logger
() {
deactivate
(); }
50
51
//
52
// LoggerConfig
53
//
54
LoggerConfig::LoggerConfig
()
55
{
56
// Turn on logging if EXO_LOG is set as non-zero value
57
_enabled = safecast<bool>(std::getenv(
"EXO_LOG"
),
false
);
58
}
59
60
void
LoggerConfig::configure
(
const
hermes::Source
*source,
hermes::Source::Setting
&setting)
const
61
{
62
// Let's ignore hermes::Sources if that is not a exo logger
63
if
(
auto
logger =
dynamic_cast<
const
Logger
*
>
(source))
64
{
65
configure
(logger, setting);
66
}
67
}
68
69
void
LoggerConfig::configure
(
const
Logger
*,
hermes::Source::Setting
&setting)
const
70
{
71
if
(_enabled)
72
{
73
// Enable all catagories
74
setting.
accept_all
();
75
}
76
else
77
{
78
// Disable all catagories
79
setting.
reject_all
();
80
}
81
}
82
83
}
// namespace exo
ConsoleReporter.h
exo::LoggerConfig::configure
void configure(const hermes::Source *, hermes::Source::Setting &) const final
Definition
Log.cpp:60
exo::LoggerConfig::LoggerConfig
LoggerConfig()
Definition
Log.cpp:54
exo::Logger
Logger Implementation.
Definition
Log.h:31
exo::Logger::Logger
Logger(hermes::Context *ctx)
Definition
Log.cpp:48
exo::Logger::~Logger
~Logger()
Definition
Log.cpp:49
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::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::accept_all
void accept_all(void)
Definition
SourceSetting.h:77
hermes::SourceSetting::reject_all
void reject_all(void)
Definition
SourceSetting.h:68
exo
Definition
CircleExporter.h:25
Log.h
compiler
exo
src
Log.cpp
Generated by
1.9.8