Skip to content

First release of cpplogger

Latest

Choose a tag to compare

@sodeprecated sodeprecated released this 01 Jun 17:46
· 15 commits to master since this release
c87d9bc

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::error structure inherited from std::exception that holds all errors and has own stack for easier tracing with Trace macro.
  • logger::log_message_type enum with common log types.
  • logger::kModifier enum with modifiers that you could apply to your console output. See more about this in example section.
  • logger::style typedef for std::vector<kModifier> with overloaded operator<<.

Functions:

  • logger::BindConsoleStyle(s, args...) (args must be instances of logger::kModifier) creates a new logger::style with name s and modifiers args.... Returns true if new style was successfully created. More information about styles in example section.
  • logger::BindLogDirectory(s) this function redefine default(project working directory) logging directory to s (s must 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 overloaded operator<< and put them instead of %v in string. logger:: kModifier in argument list is undefined behaviour. Returns true if everything OK with console output.
  • Trace(x) takes logger::error as argument and push to error's stack current filepath, function name and line where Trace was called. Returns logger::error.
  • FileLog(type, args...) takes logger::log_message_type as first argument. Creates folders in format logs/{year}/{month}/ddmmyyyy.log and outputs(in specific format) all variables provided to the function(new line for each variable).
  • DEBUG_ONLY disables file and console output. Type #define DEBUG_ONLY before(!) including cpplogger files.
  • OS_WIN/OS_UNIX determines current working system.

Platforms:

  • Windows
  • MacOs
  • Linux

Example:

Parsing rules:

Variables

  • %v Variables and modifiers are put instead of ‘%v’ in the order that they are specified in arguments list. Variable must has overloaded operator<<.

Date/Time

  • %h puts current hour in format of two digits e.g 00,05,13
  • %m puts current minute in format of two digits e.g 00,10,59
  • %s puts current second in format of two digits e.g 00,10,59
  • %dd puts day in format of two digits e.g. 01,02,12
  • %mm puts month in format of two digits e.g. 01,02,12
  • %yy puts year in format of two digits e.g. 19,20,21
  • %yyyy puts day in format of four digits e.g. 2019,2020,2021

Macros

  • %FILE puts current filename (!without path)

  • %FUNC puts current function name

  • %LINE puts current line in source file

  • %PATH puts full path to the current file including filename

  • %% puts %

Class

  • %.ClassName( ... %) Apply logger::style to 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!