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
26namespace
27{
28
34template <typename T> T safecast(const char *, const T &);
35
36template <> 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//
46namespace luci
47{
48
51
52} // namespace luci
53
54//
55// LoggerConfig
56//
57namespace luci
58{
59
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
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
81{
82 setting.reject_all();
85 if (_show_warn)
86 {
88 }
91}
92
93} // namespace luci
Logging controller.
Definition Context.h:40
Source::Registry * sources(void)
Definition Context.h:55
MessageBus * bus(void)
Definition Context.h:48
void accept_upto(uint16_t lv)
Message Source.
Definition Source.h:35
void deactivate(void)
Definition Source.cpp:49
void activate(Registry *, MessageBus *)
Definition Source.cpp:37
Filter filter(const SeverityCategory &cat)
void configure(const hermes::Source *, hermes::Source::Setting &) const final
Definition Log.cpp:71
Logger Implementation.
Definition Log.h:29
Logger(hermes::Context *ctx)
Definition Log.cpp:49
@ FATAL
Definition Severity.h:33
@ ERROR
Definition Severity.h:34
@ VERBOSE
Definition Severity.h:37
@ INFO
Definition Severity.h:36
@ WARN
Definition Severity.h:35
static UserSettings * settings()