0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
logging.cc
Go to the documentation of this file.
1/**
2 * @file src/util/logging.cc
3 *
4 * Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "logging.h"
20
21#include "util.h"
22
23#include <string>
24
26
27logger_type_t logger_type(logger_type_t type)
28{
29 static logger_type_t logger_type_singleton_{logger_type_t::text};
30
31 if (type != logger_type_t::get) {
32 logger_type_singleton_ = type;
33 }
34
35 return logger_type_singleton_;
36}
37
38std::string to_string(logger_type_t type)
39{
40 switch (type) {
41 case logger_type_t::text:
42 return "text";
43 case logger_type_t::json:
44 return "json";
45 case logger_type_t::get:
46 return "get";
47 default:
48 return "<unknown>";
49 }
50}
51
52std::string to_string(spdlog::level::level_enum level)
53{
54 switch (level) {
55 case spdlog::level::level_enum::critical:
56 return "critical";
57 case spdlog::level::level_enum::debug:
58 return "debug";
59 case spdlog::level::level_enum::err:
60 return "err";
61 case spdlog::level::level_enum::info:
62 return "info";
63 case spdlog::level::level_enum::trace:
64 return "trace";
65 case spdlog::level::level_enum::warn:
66 return "warn";
67 default:
68 return "<unknown>";
69 }
70}
71
72void escape_json_string(std::string &s)
73{
74 clanguml::util::replace_all(s, "\\", "\\\\");
75 clanguml::util::replace_all(s, "\"", "\\\"");
76 clanguml::util::replace_all(s, "\n", "");
77 clanguml::util::replace_all(s, "\r", "");
78 clanguml::util::replace_all(s, "\t", " ");
79 clanguml::util::replace_all(s, "\b", " ");
80}
81} // namespace clanguml::logging