Giter Club home page Giter Club logo

c-log's Introduction

c-log

Overview

Lightweight (single header file) C module implementing logging. The only dependency is the stdio.h providing fprintf().

The module provides 5 logging macros: error, warn, info, debug, and trace. There is no fatal level. If you want to fatal, then you should probably panic.

The macros do not have popular log_ prefix. Why? Because the names are quite self explanatory. There is no need to clutter the code with the extra log_ prefix. The warn macro conflicts with the warn() function from the err.h. However, let's be honest, no one uses err.h as the functions it provides are pretty much useless.

The module is not thread safe. If you want thread safety, then you must implement it on your own.

Installation

Simply copy the log.h file to your project.

Configuration

The module is statically configurable during the compilation time. There are 5 following configuration macros (alphabetical order):

  • LOG_COLOR - if defined, log level will be printed in color. If you don't like the default colors simply edit proper macros in the log.h file.
  • LOG_LEVEL - log level. Valid values are:
    • 0 - no logs.
    • 1 - only errors.
    • 2 - errors and warnings.
    • 3 - errors, warnings, and infos.
    • 4 - errors, warnings, infos and debugs,
    • 5 - errors, warnings, infos, debugs, and traces.
  • LOG_PREFIX - optional logging prefix. If defined in the Makefile or command line, remember to double quote, for example, -DLOG_PREFIX="\"your prefix:\""
  • LOG_STREAM - stream for logging. The default one is stderr.
  • LOG_TIME - if defined, the log will include the time. The time format is custom format. The user must provide implementation for the struct log_time log_time(void); function. For more details check the documentation in the log.h file.

The configuration can also be done per source file scope, which is sometimes desired, especially for the LOG_PREFIX. In such a case simply configure the module before include. Example:

#define LOG_PREFIX "my_prefix: "
#define LOG_LEVEL 5
#include "log.h"

Example

Check main.c file.

c-log's People

Contributors

m-kru 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.