Skip to content

ZeyadOsama/LoggerCPP

Repository files navigation

LoggerCPP

CI Actions Status stable contributions-welcome-orange

About

C++ Logging System.

Usage

In your CMakeLists.txt file add these lines

add_subdirectory(logger)
include_directories(logger/include)

Then add this header in the file you'd like to have your parser at

#include <logger/LoggerCPP.h>

using namespace logger;

Configurations

Configuration List

You should create firstly a ConfigurationList to store all your configurations.

// ConfigurationList instance
Configuration::ConfigurationList cl;

Output

You can find all output streams at at OUTPUT_STREAM::<output_stream>

OUTPUT_STREAM::CONSOLE
OUTPUT_STREAM::FILE
// Configure the output objects
Configuration::RegisterOutput(cl, "<output-concrete>");
// Example
Configuration::RegisterOutput(cl, OUTPUT_STREAM::CONSOLE);

Option

You can find all options at OPTIONS::<option>

OPTION::FILE_NAME
OPTION::MAX_FILES
// Configure the Option objects
Configuration::RegisterOption(cl, "<option>", "value");
// Example
Configuration::RegisterOption(cl, OPTION::FILE_NAME, "log.txt");

Manager

Setting Default Severity
// Set Default Severity
Manager::SetDefaultSeverity(DEBUG);
Changing Severity For a Channel
// Changing Severity 
Manager::Get("<channel-name>")->SetSeverity(NOTE);

<channel-name> is the name you pass as a parameter for the Logger object.

Logger l("<channel-name>");
Terminating LoggerCPP
// Terminating
Manager::Terminate();

Logger Object

Creating Logger Object
// Create Logger object
Logger l("<channel-name>");
Using Logger Object
l.notice() << "<message>";
l.debug() << "<message>";
l.crtic() << "<message>";
l.error() << "<message>";
l.info() << "<message>";
l.warn() << "<message>";

After <logger-object>.<function> << you can enter anything normally as using std::cout <<

Output

LoggerCPP outputs a folder named log containing the latest MAX_FILES number log files. You can change MAX_FILES default value which is MAX_FILES to any other value using:

// Example
Configuration::RegisterOption(cl, OPTION::MAX_FILES, "<MAX_FILES>");

Files are named as <current-timestamp>.log

2020-08-17 15:55:35.584.log

N.B. .log is the default extension for LoggerCPP.

You can change filename default value to any other value using:

// Example
Configuration::RegisterOption(cl, OPTION::FILE_NAME, "<filename>.<extension>");

Example Output File

2020-08-17 15:55:35.585  Main.Example DBUG This is a debug message.
2020-08-17 15:55:35.585  Main.Example INFO This is an info message.
2020-08-17 15:55:35.585  Main.Example NOTE This is a note message.
2020-08-17 15:55:35.585  Main.Example WARN This is a warning message.
2020-08-17 15:55:35.585  Main.Example EROR This is an error message.
2020-08-17 15:55:35.585  Main.Example CRIT This is a critical message.

Versioning

When installing LoggerCPP, require it's version. For us, this is what major.minor.patch means:

  • major - MAJOR breaking changes; includes major new features, major changes in how the whole system works, and complete rewrites; it allows us to considerably improve the product, and add features that were previously impossible.
  • minor - MINOR breaking changes; it allows us to add big new features.
  • patch - NO breaking changes; includes bug fixes and non-breaking new features.

Changelog

For all-time versions, please see the CHANGELOG file.

License

This project is licensed under the MIT License - see the LICENSE file for details