Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
logger.cpp File Reference

The file containing the logic for the logger. More...

#include "logger.h"
#include "plugins/luaheaders.h"
#include <unordered_map>

Functions

std::string replaceMinecraftEscapes (const std::string &s)
 
void logAtLevel (LogLevel level, std::string format, va_list args)
 Logs a format and its args at a certain level.
 

Variables

LogLevel LOGLEVEL
 The current stored loglevel.
 
const std::unordered_map< LogLevel, std::pair< std::string, std::string > > LEVELS
 Mappings for loglevel enum.
 
const std::unordered_map< char, std::stringNOTCHIAN_TO_ANSI
 

Detailed Description

The file containing the logic for the logger.

Author
Lygaen
Version
0.1
Date
2023-12-16

Function Documentation

◆ logAtLevel()

void logAtLevel ( LogLevel level,
std::string format,
va_list args )

Logs a format and its args at a certain level.

Parameters
levelthe level to log to
formatthe format of the log
argsthe arguments of the log

Variable Documentation

◆ LEVELS

Initial value:
{
{LogLevel::INFO, {"INFO", INFO_COLOR}},
{LogLevel::WARN, {"WARN", WARN_COLOR}},
}
@ 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
@ PLUGIN
Plugin level.
Definition logger.h:112
#define INFO_COLOR
ANSI color for info level in the console.
Definition logger.h:60
#define DEBUG_COLOR
ANSI color for debug level in the console.
Definition logger.h:66
#define ERROR_COLOR
ANSI color for error level in the console.
Definition logger.h:42
#define PLUGIN_COLOR
ANSI color for plugins.
Definition logger.h:54
#define WARN_COLOR
ANSI color for warn level in the console.
Definition logger.h:48
#define FATAL_COLOR
ANSI color for fatal level in the console.
Definition logger.h:36

Mappings for loglevel enum.

For ease of use, instead of having a giant switch case, we have this map. The first part of the pair in the values is the string representation of the level and the second one is the color associated with that same level.

◆ NOTCHIAN_TO_ANSI

Initial value:
{
{'0', "\033[90m"},
{'1', "\033[34m"},
{'2', "\033[32m"},
{'3', "\033[36m"},
{'4', "\033[31m"},
{'5', "\033[35m"},
{'6', "\033[33m"},
{'7', "\033[37m"},
{'8', "\033[90m"},
{'9', "\033[94m"},
{'a', "\033[92m"},
{'b', "\033[96m"},
{'c', "\033[91m"},
{'d', "\033[95m"},
{'e', "\033[93m"},
{'f', "\033[97m"},
{'k', RESET_COLOR},
{'l', "\033[1m"},
{'m', "\033[9m"},
{'n', "\033[24m"},
{'o', "\033[3m"},
{'r', RESET_COLOR},
}
#define RESET_COLOR
ANSI reset color.
Definition logger.h:25