$darkmode
logger.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
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  * SPDX-License-Identifier: Apache-2.0
17  */
34 #pragma once
35 #ifndef CLOE_CORE_LOGGER_HPP_
36 #define CLOE_CORE_LOGGER_HPP_
37 
38 #include <functional> // for function<>
39 #include <memory> // for shared_ptr<>
40 #include <string> // for string
41 
42 #include <fable/enum.hpp> // for FABLE_ENUM_SERIALIZATION
43 
44 #pragma GCC diagnostic push
45 #pragma GCC diagnostic ignored "-Wconversion"
46 #include <spdlog/spdlog.h>
47 #pragma GCC diagnostic pop
48 
49 // clang-format off
50 FABLE_ENUM_SERIALIZATION(spdlog::level::level_enum, ({
51  {spdlog::level::level_enum::trace, "trace"},
52  {spdlog::level::level_enum::debug, "debug"},
53  {spdlog::level::level_enum::info, "info"},
54  {spdlog::level::level_enum::warn, "warning"},
55  {spdlog::level::level_enum::err, "error"},
56  {spdlog::level::level_enum::critical, "fatal"},
57  {spdlog::level::level_enum::off, "off"},
58 }))
59 // clang-format on
60 
61 namespace cloe {
62 
103 using Logger = std::shared_ptr<spdlog::logger>;
104 
117 using LogLevel = spdlog::level::level_enum;
118 
119 namespace logger {
120 
128 Logger get(std::string name);
129 
176 void set_factory(std::function<Logger(std::string)> factory);
177 
187 void set_level(LogLevel l);
188 
193 LogLevel into_level(std::string s);
194 
199 std::string to_string(LogLevel l);
200 
201 } // namespace logger
202 } // namespace cloe
203 
204 #endif // CLOE_CORE_LOGGER_HPP_
FABLE_ENUM_SERIALIZATION(spdlog::level::level_enum,({ {spdlog::level::level_enum::trace, "trace"}, {spdlog::level::level_enum::debug, "debug"}, {spdlog::level::level_enum::info, "info"}, {spdlog::level::level_enum::warn, "warning"}, {spdlog::level::level_enum::err, "error"}, {spdlog::level::level_enum::critical, "fatal"}, {spdlog::level::level_enum::off, "off"}, })) namespace cloe
Definition: logger.hpp:50
Definition: coordinator.hpp:36
Definition: enum_test.cpp:29