File lib/logging.c

Logging mechanisms for the UBS. This includes reading and writing logfiles, and getting the date and time, and other such things.


Included Files


Global Variable PROCNAME

char PROCNAME[128]
Included from include/ubs.h

Global Variable CUR_TIME

struct tm* CUR_TIME
Included from include/ubs.h

Global Variable GLOBAL

ubs_table GLOBAL
Included from include/ubs.h

Global Variable LOGLEVEL

int LOGLEVEL
Included from include/ubs.h

Global Function console_error()

Prints out an error message to standard error.

void console_error ( char* message, int signal )

char* message
Message to print
int signal
Exit with signal
Prototyped in: include/ubs.h
Calls: exit(), fprintf()
Called by: ubs_init()lib/common.c

Global Function console_warning()

void console_warning ( char* message )
Prototyped in: include/ubs.h
Calls: fprintf()

Global Function get_date()

Gets the current time and converts it to a string in the form MM/DD

void get_date ( char* fmt_time )

char* fmt_time
The character array that the current date will be written to
Prototyped in: include/ubs.h
Calls: localtime(), mktime(), snprintf(), time()
Called by: log_error_msg()lib/logging.c
  log_event()lib/logging.c

Global Function get_time()

Gets the current time and converts it into a string of the form HH:MM

void get_time ( char* fmt_time )

char* fmt_time
The string which will be written to
Prototyped in: include/ubs.h
Calls: localtime(), mktime(), snprintf(), time()
Called by: log_error_msg()lib/logging.c
  log_event()lib/logging.c

Global Function gettime()

This sets a global variable CUR_TIME to reflect the present time

void gettime ( void )
Prototyped in: include/ubs.h
Calls: localtime(), mktime(), time()


Global Function log_error_msg()

Frontend to the error logging mechanism. This function can be accomplished by writing to a character buffer, and simply using log_event, but it's kind of a pain that way, especially when most calls to that function are trying to do the same thing.

int log_error_msg ( int priority, char* msg, ... )

int log_error_msg
Returns whatever write_log() returns, FAIL if the priority is insufficient, FAIL if an unknown control character is used (ie, %x or something), and FAIL if an unknown debug priority is given.
int priority
Logging priority
char* msg
The format string to use.
...
Arguments to the string
Prototyped in: include/ubs.h
Calls: get_date()lib/logging.c
  get_time()lib/logging.c
  write_log()lib/logging.c
  __builtin_stdarg_start(), __builtin_va_arg(), __builtin_va_end(), atoi(), memset(), snprintf(), strncat(), strncpy(), ubs_table_data()
Called by: check_against_cur()lib/get_song.c
  check_against_log()lib/get_song.c
  check_against_queue()lib/get_song.c
  exec_proc()lib/exec_proc.c
  get_song()lib/get_song.c
  make_cache()lib/get_song.c
  parse_dir()lib/get_song.c
  record_pid()lib/logging.c
  record_status()lib/logging.c
  sig_poll()lib/common.c
  sig_quit()lib/common.c

Global Function log_event()

This function is the frontend to write_log. It allows you to basically write to either the playlist log or the error log with the same set of data structures. For the playlist log, the format is generally as follows: [date][time][filename (full path)][artist name][song title] For the error logs, the format is as such: [date][time][process name][severity][error message]

int log_event ( char* logfile, char* field1, char* field2, char* field3, int priority )

int log_event
Returns OK on success, FAIL if the loglevel indicates not to log this message, and FAIL if one of the fields contains a bracket character (will screw up parsing)
char* logfile
The target filename to log to
char* field1
A character array for the first field
char* field2
A character array for the second field
char* field3
A character array for the third field
int priority
The priority for logging information
Prototyped in: include/ubs.h
Calls: get_date()lib/logging.c
  get_time()lib/logging.c
  write_log()lib/logging.c
  atoi(), strchr(), strncpy(), ubs_table_data()

Global Function print_log()

Prints a log_entry structure to standard output.

int print_log ( struct log_entry* entry, int mode )

int print_log
Returns OK on success
struct log_entry* entry
The entry to print out
int mode
The output mode
Prototyped in: include/ubs.h
Calls: printf()

Global Function read_log()

Given a single line from a logfile (bracket delimited), it will break it up into the respective components and place this data in a structure.

int read_log ( struct log_entry* entry, char* logbuf )

int read_log
Returns OK on success, FAIL if any single parse fails
struct log_entry* entry
The structure to be filled in
char* logbuf
 
char *logfile A single line from a properly formatted logfile

Prototyped in: include/ubs.h
Calls: strchr(), strncpy()
Called by: check_against_log()lib/get_song.c


Global Function record_pid()

Record the process ID so that other daemons know where to find us. By default, this file is var/NAME.pid, where NAME is the PROCNAME of the daemon

int record_pid ( int pid )

int record_pid
Returns OK on success, NO_FILE if the pid file can't be opened.
int pid
The current proccess ID (pid)
Prototyped in: include/ubs.h
Calls: log_error_msg()lib/logging.c
  fclose(), fopen(), fprintf(), snprintf()

Global Function record_status()

Records the current status of the daemon. This is a bit sloppy at the moment. Basically, whenever the program feels like it, it can record its status, which gets read by the UBS shell and other fun things. By default, the file that will be written to is called var/NAME.status, where NAME is the process name of the daemon. The main UBS daemons call this function after successfully starting, and at the bottom of each infinite while() loop.

int record_status ( char* msg )

int record_status
Returns OK on success, NO_FILE if the status file can't be opened
char* msg
The string to write to the status file
Prototyped in: include/ubs.h
Calls: log_error_msg()lib/logging.c
  fclose(), fopen(), fprintf(), snprintf()
Called by: sig_quit()lib/common.c

Global Function write_log()

The ugly side of log_event. This takes in a log_entry structure and appends it to the end of a logfile. This is rather cumbersome to access directly, and is usually only called via log_entry.

int write_log ( struct log_entry* entry, char* logfile )

struct log_entry* entry
The log entry structure (three character values, a date, and a time) to be written to the file
char* logfile
The filename to log to
int write log Returns OK on success, NO_FILE if the logfile cannot be opened

Prototyped in: include/ubs.h
Calls: fclose(), fopen(), fprintf()
Called by: log_error_msg()lib/logging.c
  log_event()lib/logging.c