·
15 commits
to master
since this release
Welcome to cpplogger!
cpplogger will bring new colors to your life! Make simple console output more exciting just in a few lines of code.
Getting started:
Just include one log.hpp that you can find in release folder on github.
Namespace:
- cpplogger works in
logger::namespace
Types:
logger::errorstructure inherited fromstd::exceptionthat holds all errors and has own stack for easier tracing withTracemacro.logger::log_message_typeenum with common log types.logger::kModifierenum with modifiers that you could apply to your console output. See more about this in example section.logger::styletypedef forstd::vector<kModifier>with overloadedoperator<<.
Functions:
logger::BindConsoleStyle(s, args...)(args must be instances oflogger::kModifier) creates a newlogger::stylewith namesand modifiersargs.... Returnstrueif new style was successfully created. More information about styles in example section.logger::BindLogDirectory(s)this function redefine default(project working directory) logging directory tos(smust be a valid path, doesn't matter relative or full).
Macros:
ConsoleLog(s, args...)takes string as first argument (See in description below more about parsing rules), then takes variable that has overloadedoperator<<and put them instead of%vin string.logger:: kModifierin argument list is undefined behaviour. Returnstrueif everything OK with console output.Trace(x)takeslogger::erroras argument and push to error's stack current filepath, function name and line whereTracewas called. Returnslogger::error.FileLog(type, args...)takeslogger::log_message_typeas first argument. Creates folders in formatlogs/{year}/{month}/ddmmyyyy.logand outputs(in specific format) all variables provided to the function(new line for each variable).DEBUG_ONLYdisables file and console output. Type#define DEBUG_ONLYbefore(!) including cpplogger files.OS_WIN/OS_UNIXdetermines current working system.
Platforms:
- Windows
- MacOs
- Linux
Example:
Parsing rules:
Variables
%vVariables and modifiers are put instead of ‘%v’ in the order that they are specified in arguments list. Variable must has overloadedoperator<<.
Date/Time
%hputs current hour in format of two digits e.g 00,05,13%mputs current minute in format of two digits e.g 00,10,59%sputs current second in format of two digits e.g 00,10,59%ddputs day in format of two digits e.g. 01,02,12%mmputs month in format of two digits e.g. 01,02,12%yyputs year in format of two digits e.g. 19,20,21%yyyyputs day in format of four digits e.g. 2019,2020,2021
Macros
-
%FILEputs current filename (!without path) -
%FUNCputs current function name -
%LINEputs current line in source file -
%PATHputs full path to the current file including filename -
%%puts%
Class
%.ClassName( ... %)Applylogger::styleto the string enclosed between%.ClassName(and%). Supports nested classes. Class name shouldn't contain%because of undefined behaviour. Classes without close bracket%)are undefined behaviour.
All other symbols are put as is!