C logger

0.1

Author:
Mao Yu (http://www.mao-yu.com)
Date:
Created: Saturday, June 19, 2010
Updated: Saturday, June 26, 2010
Purpose:
Provides a simple interface to log messages to file, console, and/or a callback. Useful for debugging purposes or as a general logging interface to simple apps.
Installation:
  1. Downloads:
  2. Add header and source file to your project
Usage:
An example program:
 #include <stdio.h>
 #include "logger.h"
 #define LOG(LVL,...) log_log(LVL,__FILE__,__FUNCTION__ ,__LINE__,__VA_ARGS__)

 void test_cb(LogStr msg){
        printf("-+-+-+");
        fputs(msg,stdout);
 }

 int main(int argc, char *argv[]){
        if( log_init("test.log",LOGBOOL_FALSE,test_cb) != LOGRET_OK )
                return -1;

        LOG(1,"---Testing logging functionality!");
        LOG(11,"---Can't see this! (log level is higher than default)");

        log_setlevel(11);
        LOG(11,"---Now can see this!");

        log_setlevel_console(10);
        LOG(11,"---Now only shown in file and cb!");

        log_end();
 }
Running this program will result in this in the console:
logger.c(206)[main]---Testing logging functionality!
-+-+-+logger.c(206)[main]---Testing logging functionality!
logger.c(210)[main]---Now can see this!
-+-+-+logger.c(210)[main]---Now can see this!
-+-+-+logger.c(213)[main]---Now only shown in file and cb!
And show this in test.log
logger.c(206)[main]---Testing logging functionality!
logger.c(210)[main]---Now can see this!
logger.c(213)[main]---Now only shown in file and cb!
See here for full API documentation.
License
This is public domain code