Skip to content

odundar/simple_cpp_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple_cpp_logger

This is a very straight forward CPP logger intended to reuse for basic projects to log messages on Console or determined file with determined message level including file name and line number.

CMake Integration

Add Logger as submodule

git add submodule https://github.com/odundar/simple_cpp_logger.git <path>

Include files to CMake source files list.

set (LOGGER_DIR ${PROJECT_SOURCE_DIR}/libs/simple_cpp_logger)
include_directories(${LOGGER_DIR})

set(LOGGER_SRC ${LOGGER_DIR}/Logger.hpp ${LOGGER_DIR}/Logger.cpp)

add_executable(application_binary app.cpp ${LOGGER_SRC})

You are good to go.

How to use Logger.

This is a singleton design to keep File resources available through all objects and make sure single object can be accessiable by different objects at the same time using shared_ptr.

For example, if you read logger configurations from a JSon file below could be a code snipped you can use.

    #include "Logger.hpp"

    auto logger = Logger::GetInstance();
    
    auto logLevelStr = "ERROR"; // or WARN, DEBUG, INFO
    auto logLevel = logger->GetLogLevel(logLevelStr);

    auto logFile = "/home/user/logs/applog.txt";

    auto logOutputStr = "FILE"; // or CONSOLE
    auto logOutput = logger->GetLogOutput(logOutputStr);

    // One time log preferences
    logger->SetLogPreferences(logFile, logLevel, logOutput);
    

LogLevel, LogFile, LogOutput are configured with SetLogPreferences method.

When you need to call Log method below sample can be used:

auto logger = Logger:GetInstance();

logger->Log(__FILE__, __LINE__, "Wrong Input Type Valid Values: A Z", LogLevel::ERROR);

About

A basic c++ logger

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages