2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 // TODO Extract these lexical conversion routines as a library
28 * @brief Convert C-string as a value of type T
30 * safecast(s, v) returns v if s is nullptr.
32 template <typename T> T safecast(const char *, const T &);
34 template <> bool safecast<bool>(const char *s, const bool &value)
36 return (s == nullptr) ? value : (std::stoi(s) != 0);
47 Logger::Logger(hermes::Context *ctx) { activate(ctx->sources(), ctx->bus()); }
48 Logger::~Logger() { deactivate(); }
50 } // namespace tflchef
58 LoggerConfig::LoggerConfig()
60 // Turn on logging if TFLCHEF_LOG is set as non-zero value
61 _enabled = safecast<bool>(std::getenv("TFLCHEF_LOG"), false);
64 void LoggerConfig::configure(const hermes::Source *source, hermes::Source::Setting &setting) const
66 // Let's ignore hermes::Sources if that is not a moco logger
67 if (auto logger = dynamic_cast<const Logger *>(source))
69 configure(logger, setting);
73 void LoggerConfig::configure(const Logger *, hermes::Source::Setting &setting) const
77 // Enable all catagories
82 // Disable all catagories
87 } // namespace tflchef