Logo Tesseroids 1.0: User Manual and API Documentation

src/c/logger.h File Reference

Functions to set up logging. More...

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  LOGGER
 Keep the information on the global logger. More...

Defines

#define LOG_DEBUG   0
 Logging level for debug messages.
#define LOG_INFO   1
 Logging level for general information.
#define LOG_WARNING   2
 Logging level for warning messages.
#define LOG_ERROR   3
 Logging level for error messages.

Functions

void log_init (int level)
 Setup logging to stderr.
void log_tofile (FILE *logfile, int level)
 Set logging to a file.
void log_debug (const char *fmt,...)
 Log a message at debug level.
void log_info (const char *fmt,...)
 Log a message at info level.
void log_warning (const char *fmt,...)
 Log a message at warning level.
void log_error (const char *fmt,...)
 Log a message at error level.

Variables

LOGGER logger
 Global logger struct.

Detailed Description

Functions to set up logging.

Example:

#include "logger.h"

void my_func(){
    log_info("From my_func!\n");
}

int main(){
    log_init(LOG_DEBUG);
    log_debug("debug line. The code is %d", LOG_DEBUG);
    log_info("info line. The code is %d", LOG_INFO);
    log_warning("warning line. The code is %d", LOG_WARNING);
    log_error("error line. The code is %d", LOG_ERROR);
    return 0;
}

Will print:

DEBUG: debug line. The code is 0
info line. The code is 1
WARNING: warning line. The code is 2
ERROR: error line. The code is 3

If function log_init() is not called than logging is disabled and no messages will be printed to stderr.

Author:
Leonardo Uieda
Date:
31 Jan 2011

Function Documentation

void log_debug ( const char *  fmt,
  ... 
)

Log a message at debug level.

Pass parameters in the same format as printf()

Prints a newline at the end.

void log_error ( const char *  fmt,
  ... 
)

Log a message at error level.

Pass parameters in the same format as printf()

Prints a newline at the end.

void log_info ( const char *  fmt,
  ... 
)

Log a message at info level.

Pass parameters in the same format as printf()

Does not print "INFO: " in front of the message when logging

Prints a newline at the end.

void log_init ( int  level  ) 

Setup logging to stderr.

Parameters:
level level of logging to be made. Can be one of:

  • LOG_DEBUG
  • LOG_INFO
  • LOG_WARNING
  • LOG_ERROR
void log_tofile ( FILE *  logfile,
int  level 
)

Set logging to a file.

Parameters:
logfile FILE pointer to the already open file to log to.
level level of logging to be made to the file. Can be one of:

  • LOG_DEBUG
  • LOG_INFO
  • LOG_WARNING
  • LOG_ERROR
void log_warning ( const char *  fmt,
  ... 
)

Log a message at warning level.

Pass parameters in the same format as printf()

Prints a newline at the end.


Variable Documentation

Global logger struct.

Only declare in the main program!

Generated on Tue Apr 26 12:17:07 2011 for Tesseroids 1.0: User manual and API documentation by doxygen 1.6.3