Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

The Logging Library
[Helper Components]

Library that provides a method logging messages to stdout, stderr, syslogd, or a file. More...


Files

file  log_lib.c
 This is the implementation of the Logging Library.

file  log_lib.h
 This is the header for the Logging Library.


Defines

#define LOG_LIB_BUFF_SIZE   150
 The maximum length of the log message string.

#define LOGSYSLOG   0x08
 Used to log to syslogd.

#define LOGSTDERR   0x04
 Used to log to stderr.

#define LOGSTDOUT   0x02
 Used to log to stdout.

#define LOGFILE   0x01
 Used to log to a file.


Functions

void logmessage (char *message, int unsigned location, char *process_name, char *log_file_name, char *filename, int line_num, char *function)
 Writes log messages to stderr, stdout, syslogd, or a file.


Detailed Description

Library that provides a method logging messages to stdout, stderr, syslogd, or a file.

Over the years, I have come to realize that logging is an extremely important part of an application. Inevitably, a situation arises when not every piece of the process is configured properly to work with its environment. Log files are invaluable in situations of this nature. When a catastrophe occurs, the log gives you the information needed to avoid future problems. With major processes in Linux, it is helpful to have this information presented chronologically in the same file. In Linux, this functionality is provided by the syslog daemon (syslogd).

In the early stages of development it is also very common to log activities. Most developers use the occasional print statement that allows them to view the current progress or state of the application. Capturing all of the data that defines the state of the program and then printing it, can often be tedious.

There are also situations where a developer might want to print the log message to the screen and write to a file. To perform this task by hand would take twice as many lines of code.

To help solve both of these problems I created the logging library. This module makes logging messages much easier while providing more helpful information. The library uses a #define macro to make the function calls shorter.

The #define macro in the program that is using the module:

#define LOGMESSAGE(string, location) logmessage(string, location,\ ALSAD_PROC_NAME, ALSAD_LOG_FILE, __FILE__,\ __LINE__, __FUNCTION__);

It is also necessary to #define ALSAD_PROC_NAME and ALSAD_LOG_FILE.

These two variables are the name of the calling process and the name and path of the log file the process should write to, respectively.

A call such as:

LOGMESSAGE("Hello World!", LOGSTDERR | LOGSYSLOG);

logs and formats 'Hello World!' along with the other function parameters to stderr and syslogd.


Define Documentation

#define LOG_LIB_BUFF_SIZE   150
 

The maximum length of the log message string.

#define LOGFILE   0x01
 

Used to log to a file.

#define LOGSTDERR   0x04
 

Used to log to stderr.

#define LOGSTDOUT   0x02
 

Used to log to stdout.

#define LOGSYSLOG   0x08
 

Used to log to syslogd.


Function Documentation

void logmessage char *  message,
int unsigned  location,
char *  process_name,
char *  log_file_name,
char *  filename,
int  line_num,
char *  function
 

Writes log messages to stderr, stdout, syslogd, or a file.

This function will write to any combination of the listed locations. The easiest way to use this is to #define a macro that fills in most of the parameters automatically. This is shown in the details of this library.

Parameters:
message The message to log.
location The location to log the message. This value can be any combination of ( LOGSYSLOG | LOGSTDERR | LOGSTDOUT | LOGFILE )
process_name The name of the executing process.
log_file_name The name of the file in which to write the message. NULL if not writing to a file.
filename The name of the file in which the log message resides.
line_num The line number of the log message.
function The function from which the log message was called.


Generated on Thu Dec 16 23:07:32 2004 for alsad by doxygen 1.3.6