SNode.C
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025, 2026
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef LOGGER_LOGGER_H
43#define LOGGER_LOGGER_H
44
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
46
47#ifdef __GNUC__
48#pragma GCC diagnostic push
49#ifdef __has_warning
50#if __has_warning("-Wdocumentation-unknown-command")
51#pragma GCC diagnostic ignored "-Wdocumentation-unknown-command"
52#endif
53#else
54#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
55#endif
56#endif
57#include <easylogging++.h> // IWYU pragma: export
58#ifdef __GNUC__
59#pragma GCC diagnostic pop
60#endif
61
62#include <string>
63
64#endif /* DOXYGEN_SHOULD_SKIP_THIS */
65
66namespace Color {
67
91
92 std::ostream& operator<<(std::ostream& os, const Code& code);
93
94 std::string operator+(const std::string& string, const Code& code);
95 std::string operator+(const Code& code, const std::string& string);
96
97} // namespace Color
98
99namespace logger {
100
101 class Logger {
102 public:
103 Logger() = delete;
104 ~Logger() = delete;
105
106 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays, modernize-avoid-c-arrays)
107 static void init();
108
109 static void setLogLevel(int level);
110
111 static void setVerboseLevel(int level);
112
113 static void logToFile(const std::string& logFile);
114
115 static void setQuiet(bool quiet = true);
116
117 static void setCustomFormatSpec(const char* format, const el::FormatSpecifierValueResolver& resolver);
118
119 static void setDisableColor(bool disableColorLog = true);
120
121 static bool getDisableColor();
122
123 protected:
124 static bool disableColorLog;
125
126 friend std::ostream& Color::operator<<(std::ostream& os, const Color::Code& code);
127
128 friend std::string Color::operator+(const std::string& string, const Color::Code& code);
129 friend std::string Color::operator+(const Color::Code& code, const std::string& string);
130 };
131
132} // namespace logger
133
134#endif // LOGGER_LOGGER_H
static bool disableColorLog
Definition Logger.h:124
static void setDisableColor(bool disableColorLog=true)
Definition Logger.cpp:84
static void logToFile(const std::string &logFile)
Definition Logger.cpp:143
static void setVerboseLevel(int level)
Definition Logger.cpp:137
static void setCustomFormatSpec(const char *format, const el::FormatSpecifierValueResolver &resolver)
Definition Logger.cpp:80
~Logger()=delete
static void setLogLevel(int level)
Definition Logger.cpp:100
static void init()
Definition Logger.cpp:54
static void setQuiet(bool quiet=true)
Definition Logger.cpp:152
Logger()=delete
static bool getDisableColor()
Definition Logger.cpp:94
int main(int argc, char *argv[])
Definition Logger.h:66
Code
Definition Logger.h:68
@ FG_LIGHT_CYAN
Definition Logger.h:84
@ BG_DEFAULT
Definition Logger.h:89
@ FG_LIGHT_YELLOW
Definition Logger.h:81
@ FG_LIGHT_GREEN
Definition Logger.h:80
@ FG_DARK_GRAY
Definition Logger.h:78
@ FG_LIGHT_RED
Definition Logger.h:79
@ FG_LIGHT_GRAY
Definition Logger.h:77
@ FG_LIGHT_MAGENTA
Definition Logger.h:83
@ FG_LIGHT_BLUE
Definition Logger.h:82
@ FG_YELLOW
Definition Logger.h:73
@ FG_DEFAULT
Definition Logger.h:69
@ FG_MAGENTA
Definition Logger.h:75
std::string operator+(const std::string &string, const Code &code)
Definition Logger.cpp:168
std::string operator+(const Code &code, const std::string &string)
Definition Logger.cpp:172