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
20
21#include <cstdlib>
22#include <iostream>
23
24// TODO Extract these lexical conversion routines as a library
25namespace
26{
27
33template <typename T> T safecast(const char *, const T &);
34
35template <> bool safecast<bool>(const char *s, const bool &value)
36{
37 return (s == nullptr) ? value : (std::stoi(s) != 0);
38}
39
40} // namespace
41
42namespace exo
43{
44
45//
46// Logger
47//
50
51//
52// LoggerConfig
53//
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
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
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
void configure(const hermes::Source *, hermes::Source::Setting &) const final
Definition Log.cpp:60
Logger Implementation.
Definition Log.h:31
Logger(hermes::Context *ctx)
Definition Log.cpp:48
~Logger()
Definition Log.cpp:49
Logging controller.
Definition Context.h:40
Source::Registry * sources(void)
Definition Context.h:55
MessageBus * bus(void)
Definition Context.h:48
Message Source.
Definition Source.h:35
void deactivate(void)
Definition Source.cpp:49
void activate(Registry *, MessageBus *)
Definition Source.cpp:37