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 "Log.h"
18
19#include <cassert>
20#include <cstdlib>
21#include <iostream>
22
23// TODO Extract these lexical conversion routines as a library
24namespace
25{
26
32template <typename T> T safecast(const char *, const T &);
33
34template <> bool safecast<bool>(const char *s, const bool &value)
35{
36 return (s == nullptr) ? value : (std::stoi(s) != 0);
37}
38
39} // namespace
40
41//
42// Logger
43//
44namespace tflchef
45{
46
49
50} // namespace tflchef
51
52//
53// LoggerConfig
54//
55namespace tflchef
56{
57
59{
60 // Turn on logging if TFLCHEF_LOG is set as non-zero value
61 _enabled = safecast<bool>(std::getenv("TFLCHEF_LOG"), false);
62}
63
65{
66 // Let's ignore hermes::Sources if that is not a moco logger
67 if (auto logger = dynamic_cast<const Logger *>(source))
68 {
69 configure(logger, setting);
70 }
71}
72
74{
75 if (_enabled)
76 {
77 // Enable all catagories
78 setting.accept_all();
79 }
80 else
81 {
82 // Disable all catagories
83 setting.reject_all();
84 }
85}
86
87} // namespace tflchef
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
void configure(const hermes::Source *, hermes::Source::Setting &) const final
Definition Log.cpp:64
Logger Implementation.
Definition Log.h:29
Logger(hermes::Context *ctx)
Definition Log.cpp:47