Log Functions

Out of date!!!!

Introduction

The log functions are used internally to display debug information, messages, warnings and errors. The log functions can also come in handy outside libdicom.

Log Level

The variable dicom_log_level controls what messages are logged. It can be set to one of the following values:

EMERGENCY
A panic condition.
ALERT
A condition that should be corrected immediately.
CRITICAL
Critical conditions.
ERROR
Errors.
WARNING
Warnings messages.
NOTICE
Conditions that are not error conditions, but that may require special handling.
INFO
Informational messages.
DEBUG
Messages that contain information normally of use only when debugging a program.
These conditions are defined according to syslogd priority levels.

For example, if you set dicom_log_level to CRITICAL you will only see messages from conditions that are at least critical. The default level is INFO.

Log functions

void dicom_log_name(char *)

Use this function if you want your program name to show up in the log. If this function is not called, "log" will be used as default program name. If you pass a filename, only the basename will be used.

Example:

dicom_log_name(*argv);

int dicom_log_open(const char *)

Use this function if you want the log to be written to a file. This function will attempt to open the filename given and append the log to it. If it succeeds it will return 0. If not, logging continues on the default stream stderr.

void dicom_log(CONDITION,const char *)

Use this function to add a message to the log. CONDITION is one of the conditions declared in the previous section. The message will show up in the following format:

Date Time ProgramName[ProcessID]: Condition: Message

Example:

Oct 17 12:45:42 xrad[19401]: error: Unable to open file

int dicom_log_close(void)

This function closes the file you opened with dicom_log_open(). If it succeeds it will return 0. If not, logging is continued on the default stream stderr.

Common Log Usage

In most cases, you only call dicom_log_name(*argv) from your main() function, and dicom_log() whenever you want a message logged.

Prototypes from dicom.h

typedef enum
{
  EMERGENCY,
  ALERT,
  CRITICAL,
  ERROR,
  WARNING,
  NOTICE,
  INFO,
  DEBUG
}
CONDITION;

extern CONDITION dicom_log_level;

void	dicom_log_name(char *);
int	dicom_log_open(const char *);
void	dicom_log(CONDITION,const char *);
int	dicom_log_close(void);