logger.c File Reference

This file implements the logger functions. More...

#include "logger.h"
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

Include dependency graph for logger.c:

Go to the source code of this file.

Defines

#define FILE_NAME_BUF_SIZE   255

Functions

int initLogFile (const char *fileName)
 Initializes the global log file.
void closeLogFile (void)
 Closes the global log file, if one has be opened previously.
void logToFile (logLevel level, char *format, va_list fmt_args)
 Logs the given message to the global log file if it is initialized.
void loggerInitColors (void)
void wlogger (WINDOW *window, int attr, logLevel level, char *format,...)
 Prints the given message to a ncurses window, according to its log level.
void vwlogger (WINDOW *window, int attr, logLevel level, char *format, va_list fmt_args)
 Prints the given message to a ncurses window, according to its log level.
void wlog_once (WINDOW *window, int attr, char *fileName, unsigned int lineNumber, logLevel level, char *format,...)
 Prints the given message to ncurses window, according to its log level but only if the params fileName and lineNumber differ.
void logger (logLevel level, char *format,...)
 Prints the given message to stdout, according to its log level.
void vlogger (logLevel level, char *format, va_list fmt_args)
 Prints the given message to stdout, according to its log level.
void log_once (char *fileName, unsigned int lineNumber, logLevel level, char *format,...)
 Prints the given message to stdout, according to its log level but only if the params fileName and lineNumber differ.
int setLogLevel (logLevel desiredLogLevel)
 Sets a new global log level.
int increaseLogLevel (void)
 Increases the log level by one.
int decreaseLogLevel (void)
 Decreases the log level by one.
int getCurrentLogLevel (void)
 Returns the current log level as number.

Variables

int currentLogLevel = DEFAULT_LOG_LEVEL
 Holds the current log level.
pthread_mutex_t logMutex = PTHREAD_MUTEX_INITIALIZER
FILE * logFile = NULL


Detailed Description

This file implements the logger functions.

Version:
Id
logger.c,v 1.10 2008/09/18 12:59:02 prokop Exp

Definition in file logger.c.


Define Documentation

#define FILE_NAME_BUF_SIZE   255

Definition at line 32 of file logger.c.


Function Documentation

void closeLogFile ( void   ) 

Closes the global log file, if one has be opened previously.

Definition at line 53 of file logger.c.

int decreaseLogLevel ( void   ) 

Decreases the log level by one.

Returns:
1 if log level could be decreased, 0 otherwise.

Definition at line 223 of file logger.c.

int getCurrentLogLevel ( void   ) 

Returns the current log level as number.

Returns:
the current log level.

Definition at line 227 of file logger.c.

int increaseLogLevel ( void   ) 

Increases the log level by one.

Returns:
1 if log level could be increased, 0 otherwise.

Definition at line 219 of file logger.c.

int initLogFile ( const char *  fileName  ) 

Initializes the global log file.

Parameters:
fileName File name of the log file to be initialized
Returns:
1 if the file was successfully opened, 0 otherwise.

Definition at line 39 of file logger.c.

void log_once ( char *  fileName,
unsigned int  lineNumber,
logLevel  level,
char *  format,
  ... 
)

Prints the given message to stdout, according to its log level but only if the params fileName and lineNumber differ.

This should prevent repetition of identical messages. To save typing work there exist the LOGONCE macro, which automatically replaces the file name and line number with the __FILE__ and __NAME__ macro.

Parameters:
fileName The file name of the file this function is called from
lineNumber The line number this function is called from
level Message level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
... list of parameters to the format string.

Definition at line 184 of file logger.c.

void logger ( logLevel  level,
char *  format,
  ... 
)

Prints the given message to stdout, according to its log level.

Parameters:
level mesage level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
See also:
man printf
Parameters:
... list of parameters to the format string.

Definition at line 154 of file logger.c.

void loggerInitColors ( void   ) 

Definition at line 90 of file logger.c.

void logToFile ( logLevel  level,
char *  format,
va_list  fmt_args 
)

Logs the given message to the global log file if it is initialized.

Parameters:
level Log level
format message format
fmt_args format arguments

Definition at line 65 of file logger.c.

int setLogLevel ( logLevel  desiredLogLevel  ) 

Sets a new global log level.

Parameters:
desiredLogLevel The new log level, see logLevels. If the new log level is too high or too low, you will see a warning and the new log level will be set within valid range.
Returns:
1 if the new log level is valid, 0 otherwise.

Definition at line 204 of file logger.c.

void vlogger ( logLevel  level,
char *  format,
va_list  fmt_args 
)

Prints the given message to stdout, according to its log level.

Parameters:
level mesage level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
fmt_args list of parameters
See also:
man vprintf

Definition at line 164 of file logger.c.

void vwlogger ( WINDOW *  window,
int  attr,
logLevel  level,
char *  format,
va_list  fmt_args 
)

Prints the given message to a ncurses window, according to its log level.

Parameters:
window ncurses window for the message
attr ncurses attributes for the message (see attron() function of ncurses)
level mesage level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
fmt_args list of parameters
See also:
man vprintf

Definition at line 108 of file logger.c.

void wlog_once ( WINDOW *  window,
int  attr,
char *  fileName,
unsigned int  lineNumber,
logLevel  level,
char *  format,
  ... 
)

Prints the given message to ncurses window, according to its log level but only if the params fileName and lineNumber differ.

This should prevent repetition of identical messages. To save typing work there exist the WLOGONCE macro, which automatically replaces the file name and line number with the __FILE__ and __NAME__ macro.

Parameters:
window ncurses window for the message
attr ncurses attributes for the message (see attron() function of ncurses)
fileName The file name of the file this function is called from
lineNumber The line number this function is called from
level Message level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
... list of parameters to the format string.

Definition at line 132 of file logger.c.

void wlogger ( WINDOW *  window,
int  attr,
logLevel  level,
char *  format,
  ... 
)

Prints the given message to a ncurses window, according to its log level.

Parameters:
window ncurses window for the message
attr ncurses attributes for the message (see attron() function of ncurses)
level mesage level. Message will only be shown, if the global level greater than this one.
format String to be printed, possibly with format instructions.
See also:
man printf
Parameters:
... list of parameters to the format string.

Definition at line 99 of file logger.c.


Variable Documentation

int currentLogLevel = DEFAULT_LOG_LEVEL

Holds the current log level.

Definition at line 34 of file logger.c.

FILE* logFile = NULL

Definition at line 37 of file logger.c.

pthread_mutex_t logMutex = PTHREAD_MUTEX_INITIALIZER

Definition at line 36 of file logger.c.


Generated on Sun Sep 28 21:20:01 2008 for Guard by  doxygen 1.5.6