Code Monkey home page Code Monkey logo

simple-c-logger's Introduction

Simple C Logger

Dead simple logging library based off of a similar library by rxi. Designed to be as minimal and easy-to-use as possible.

Use

The library comes with five functions, all of which take an output FILE* as their first argument and a printf-style format string with parameters as following arguments. The functions are identical in all ways except for the string used as their "log-level".

void log_info   (FILE* stream, const char* format, ...);
void log_debug  (FILE* stream, const char* format, ...);
void log_warning(FILE* stream, const char* format, ...);
void log_error  (FILE* stream, const char* format, ...);
void log_fatal  (FILE* stream, const char* format, ...);

You can include the log.h and log.c files in a project directly or install the library locally with make install. Installing locally will add log.h to your local include path and add liblog.a to your local lib path so that the library can be linked-to with -llog.

Example

/* example.c */
#include <log.h>

int main(void)
{
    int foo = 0;
    log_info(stdout,    "This is a message created with log_info     foo = %d", foo++);
    log_debug(stdout,   "This is a message created with log_debug    foo = %d", foo++);
    log_warning(stdout, "This is a message created with log_warning  foo = %d", foo++);
    log_error(stdout,   "This is a message created with log_error    foo = %d", foo++);
    log_fatal(stdout,   "This is a message created with log_fatal    foo = %d", foo++);
    return 0;
}
$ make example 
mkdir -p build/
gcc -Wall -Wextra -std=c11 -c -o build/log.o log.c -O3
ar rcs build/liblog.a build/log.o
gcc -Wall -Wextra -std=c11 -o build/example example.c -I. -Lbuild/ -llog
$ ./build/example 
2017-10-25 17:45:27    INFO: This is a message created with log_info     foo = 0
2017-10-25 17:45:27   DEBUG: This is a message created with log_debug    foo = 1
2017-10-25 17:45:27 WARNING: This is a message created with log_warning  foo = 2
2017-10-25 17:45:27   ERROR: This is a message created with log_error    foo = 3
2017-10-25 17:45:27   FATAL: This is a message created with log_fatal    foo = 4

License

The Unlicense

simple-c-logger's People

Watchers

 avatar  avatar

Forkers

skyformat99

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.