Skip to content
/ log.c Public
forked from rxi/log.c

A simple logging library implemented in C99

License

Notifications You must be signed in to change notification settings

BDeliers/log.c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

log.c

A simple logging library implemented in C99

screenshot

Usage

log.c and log.h should be dropped into an existing project and compiled along with it. The library provides 6 function-like macros for logging:

log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);

Each function takes a printf format string followed by additional arguments:

log_trace("Hello %s", "world")

Resulting in a line with the given format printed to standard output:

20:18:26 TRACE src/main.c:11: Hello world

And to the output files:

2047-03-11 20:18:26 TRACE src/main.c:11: Hello world

Detailed documentation is provided in the 'log.h' file

Configure library

To alter the default settings, the library has to be compiled with the 'LOGC__USER_SETTINGS' flag. This way, a 'log_conf.h' file can be specified to alter the default settings.

Differences with the original project from rxi

The most interesting pull-requests (to me at least) have been integrated. Thanks to the following for their indirect contribution:

My changes:

  • Code indentation changed to 4 spaces
  • Added doxygen-style documentation for all functions and structures
  • Log levels enum converted to a typedef
  • Ability to configure library with the 'log_conf.h' file
  • Renamed 'udata' variables in code to more meaningful
  • Added sample source files
    • basic Is a basic example, to log to stdout and to a file
    • callbacks Is a minimal example using callbacks with different log levels
    • threading Shows a threading example

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

About

A simple logging library implemented in C99

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 100.0%