Giter Site home page Giter Site logo

c-logger's Introduction

c-logger

Simple C/Cpp macros for logging and debuging in code

Usage

Include the header file in your code, and then use the macros to log messages.

LOGGER_LOG(file,level,fmt,...) 

LOG_DEBUG(fmt,...)
LOG_INFO(fmt,...)
LOG_WARN(fmt,...)
LOG_ERROR(fmt,...)
LOG_FATAL(fmt,...) // exits the program, with exit code 1

LOG_WATCH(var) // Only for c++
LOG_WATCH_INT(var)
LOG_WATCH_FLOAT(var)
LOG_WATCH_STRING(var)
// ...

Settings

LOGGER_SETTINGS_LEVEL

  • LOGGER_LEVEL_DEBUG (default)
  • LOGGER_LEVEL_INFO
  • LOGGER_LEVEL_WARNING
  • LOGGER_LEVEL_ERROR
  • LOGGER_LEVEL_FATAL

LOGGER_SETTINGS_COLORS

  • LOGGER_COLORS_ON (default)
  • LOGGER_COLORS_OFF

Example

#define LOGGER_SETTINGS_LEVEL LOGGER_LEVEL_DEBUG    // optional
#define LOGGER_SETTINGS_COLORS LOGGER_COLORS_ON     // optional
#include "logger.h"

int main(int argc, char const *argv[])
{
    LOG_DEBUG("This is a debug message");
    LOG_INFO("Five plus five is %d", 5 + 5);
    LOG_WARN("Formating is %s", "easy");
    LOG_ERROR("This is an error message");

    for (size_t i = 0; i < 3; i++)
    {
        LOG_WATCH_INT(i);
        // LOG_WATCH(i); // Only for c++
    }

    LOG_FATAL("This is a fatal message, the program will now exit");

    puts("This will never be printed");

    return 0;
}

Output:

[DEBUG]: This is a debug message
[INFO]: Five plus five is 10
[WARNING]: Formating is easy
[ERROR]: This is an error message
[DEBUG]: i = 0
[DEBUG]: i = 1
[DEBUG]: i = 2
[FATAL]: This is a fatal message, the program will now exit

build and run with:

gcc example.c -o example && ./example

c-logger's People

Contributors

adaxiik avatar

Stargazers

 avatar  avatar

Watchers

 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.