Code Monkey home page Code Monkey logo

singlelog's Introduction

SingleLog

Description

SingleLog is a header only C++14 singleton logging library. It's fast, convenient, compiles on Windows and Linux, and does what it says on the tin.

Note

  • By design, trace level logging is only available in debug builds. In release builds the lowest logging level is debug.

Example

Using SingleLog is as easy as this:

#include "singlelog.hpp"

// Configure the logger
void SetupLogging()
{
    Uplinkzero::Logging::SingleLog * pLogger = Uplinkzero::Logging::SingleLog::GetInstance();
    pLogger->SetConsoleLogLevel(Uplinkzero::Logging::LogLevel::L_INFO);
    pLogger->SetFileLogLevel(Uplinkzero::Logging::LogLevel::L_TRACE);
    pLogger->SetLogFilePath("example.log");
}

// Logging via a local pointer
void LocalPointerLogging()
{
    std::string module = "Local pointer thread";
    Uplinkzero::Logging::SingleLog * pLogger = Uplinkzero::Logging::SingleLog::GetInstance();
    pLogger->Critical(module, "Critial message");
    pLogger->Error(module, "Error message");
    pLogger->Warning(module, "Warning message");
    pLogger->Notice(module, "Notice message");
    pLogger->Info(module, "Info message");
    pLogger->Debug(module, "Debug message");
    pLogger->Trace(module, "Trace message");
}

// Logging with macros. This is the recommended logging option.
void MacroLogging()
{
    std::string module = "MACRO thread";
    LOG_TRACE_FUNCTION();
    LOG_CRITICAL(module, "Critial message");
    LOG_ERROR(module, "Error message");
    LOG_WARNING(module, "Warning message");
    LOG_NOTICE(module, "Notice message");
    LOG_INFO(module, "Info message");
    LOG_DEBUG(module, "Debug message");
    LOG_TRACE(module, "Trace message");
}

int main()
{
    SetupLogging();
    std::thread t1(LocalPointerLogging);
    std::thread t2(MacroLogging);
    t1.join();
    t2.join();
    return 0;
}

Which, when run will produce the following in the console:

2010-12-01 13:01:12  <CRITICAL>  Local pointer thread:  Critial message
2010-12-01 13:01:12  <ERROR>  Local pointer thread:  Error message
2010-12-01 13:01:12  <CRITICAL>  MACRO thread:  Critial message
2010-12-01 13:01:12  <WARNING>  Local pointer thread:  Warning message
2010-12-01 13:01:12  <NOTICE>  Local pointer thread:  Notice message
2010-12-01 13:01:12  <ERROR>  MACRO thread:  Error message
2010-12-01 13:01:12  <INFO>  Local pointer thread:  Info message
2010-12-01 13:01:12  <WARNING>  MACRO thread:  Warning message
2010-12-01 13:01:12  <NOTICE>  MACRO thread:  Notice message
2010-12-01 13:01:12  <INFO>  MACRO thread:  Info message

And the following in the log file "example.log":

2010-12-01 13:01:12  <TRACE>  FunctionTrace:   ---> Entering function: MacroLogging
2010-12-01 13:01:12  <CRITICAL>  Local pointer thread:  Critial message
2010-12-01 13:01:12  <ERROR>  Local pointer thread:  Error message
2010-12-01 13:01:12  <CRITICAL>  MACRO thread:  Critial message
2010-12-01 13:01:12  <WARNING>  Local pointer thread:  Warning message
2010-12-01 13:01:12  <NOTICE>  Local pointer thread:  Notice message
2010-12-01 13:01:12  <ERROR>  MACRO thread:  Error message
2010-12-01 13:01:12  <INFO>  Local pointer thread:  Info message
2010-12-01 13:01:12  <WARNING>  MACRO thread:  Warning message
2010-12-01 13:01:12  <DEBUG>  Local pointer thread:  Debug message
2010-12-01 13:01:12  <NOTICE>  MACRO thread:  Notice message
2010-12-01 13:01:12  <TRACE>  Local pointer thread:  Trace message
2010-12-01 13:01:12  <INFO>  MACRO thread:  Info message
2010-12-01 13:01:12  <DEBUG>  MACRO thread:  Debug message
2010-12-01 13:01:12  <TRACE>  MACRO thread:  Trace message
2010-12-01 13:01:12  <TRACE>  FunctionTrace:   <--- Exiting function: MacroLogging

singlelog's People

Contributors

james-chapman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.