Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1
12#ifndef MINESERVER_LOGGER_H
13#define MINESERVER_LOGGER_H
14
15#include <utils/config.h>
16#include <plugins/event.h>
17#include <cstdarg>
18#include <ctime>
19
20#ifdef MINESERVER_ANSI_COLORS
25#define RESET_COLOR "\033[0m"
31#define TIME_COLOR "\033[0;90m"
36#define FATAL_COLOR "\033[1;31m"
42#define ERROR_COLOR "\033[0;31m"
48#define WARN_COLOR "\033[0;33m"
54#define PLUGIN_COLOR "\033[0;34m"
60#define INFO_COLOR "\033[0;35m"
66#define DEBUG_COLOR "\033[0;36m"
67#else
68#define RESET_COLOR ""
69#define TIME_COLOR ""
70#define FATAL_COLOR ""
71#define ERROR_COLOR ""
72#define WARN_COLOR ""
73#define PLUGIN_COLOR ""
74#define INFO_COLOR ""
75#define DEBUG_COLOR ""
76#endif
77
78// Because windows already uses the name
79#undef ERROR
80
87enum LogLevel : std::uint8_t
88{
94 ALL = 0,
100 DEBUG = 1,
106 INFO = 2,
118 WARN = 3,
124 ERROR = 4,
130 FATAL = 5,
136 OFF = 6,
137};
138
145namespace logger
146{
154 std::string getTime();
155
163 void loadConfig();
164
174 void debug(const char *format, ...);
175
187 void info(const char *format, ...);
188
200 void plugin(const char *format, ...);
201
212 void warn(const char *format, ...);
213
225 void error(const char *format, ...);
226
238 void fatal(const char *format, ...);
239
248 class PostPrintEvent : public IEvent<PostPrintEvent>
249 {
250 };
251}
252
253#endif // MINESERVER_LOGGER_H
Event interface.
Definition event.h:28
Post print event.
Definition logger.h:249
The main file for the config io.
The header-only containing event logic.
constexpr std::string_view type_name()
Gets the name of the type paramater.
Definition event.h:56
LogLevel
The LogLevel used internally by the logger.
Definition logger.h:88
@ DEBUG
Debug level.
Definition logger.h:100
@ ERROR
Error level.
Definition logger.h:124
@ FATAL
Fatal level.
Definition logger.h:130
@ INFO
Info and.
Definition logger.h:106
@ WARN
warn level
Definition logger.h:118
@ OFF
Off level, just for disabling.
Definition logger.h:136
@ ALL
All level, just for enabling.
Definition logger.h:94
@ PLUGIN
Plugin level.
Definition logger.h:112
The logging namespace.
Definition logger.h:146
void plugin(const char *format,...)
Logs something at the PLUGIN level, for plugins.
Definition logger.cpp:180
void error(const char *format,...)
Logs something at the ERROR level.
Definition logger.cpp:196
void fatal(const char *format,...)
Logs something at the FATAL level.
Definition logger.cpp:204
std::string getTime()
Get the Time as a string.
Definition logger.cpp:22
void info(const char *format,...)
Logs something at the INFO level.
Definition logger.cpp:172
void loadConfig()
Loads the loglevel from the config.
Definition logger.cpp:31
void warn(const char *format,...)
Logs something at the WARN level.
Definition logger.cpp:188
void debug(const char *format,...)
Logs something at the DEBUG level.
Definition logger.cpp:164