Giter Site home page Giter Site logo

c-logger's Introduction

C-LOGGER

Simple code for printing colored logs to the terminal or saving them to a file using C.

Usage

  • 4 log level for stdout:
DEBUG("This is debug info with color: %s", "blue");
INFO("This is info info with color: %s", "green");
ERROR("This is error info with color: %s", "red");
TRACE("This is error info with color: %s", "orange");
  • Output:

Alt text

  • In the log file storage, there are 3 log levels with limits. If the log surpasses the defined limit, the program will automatically delete the first 300 lines from the log to allow continuous writing (specified by NUMBER2DEL in the file header).
// Initialize the log with a log name and set a log size limit.
log_profile_t* log_profile = init_logger_file("mqtt_log", 1 * MB);
// Begin writing logs.
STORE_DEBUG("this is debug message!",log_profile);
STORE_INFO("this is info message!",log_profile);
STORE_ERROR("this is error message!",log_profile);
STORE_TRACE("this is trace message!",log_profile);
// Close the profile.
close_log_profile(log_profile);
  • Output:

Alt text

  • You can enable timestamp, file line info, and color output by -D option in Makefile:
    • -DUSE_DEBUG_LINE
    • -DUSE_COLOR
    • -DUSE_TIMESTAMP

Build

  • Support static library, define INCLUDE_PATH and LIBRARY_PATH then build with command:
make lib
make install

c-logger's People

Contributors

vienchau avatar

Stargazers

 avatar Minh (DeltaCross) avatar  avatar Dinh Thi Thanh Binh avatar Nguyen Quang Minh avatar LongPham avatar

Watchers

 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.