Logging mechanisms for the UBS. This includes reading and writing logfiles, and getting the date and time, and other such things.
Included Files
- #include </usr/lib/gcc-lib/i486-pc-linux-gnu/3.2.3/include/stdio.h>
- #include </usr/include/stdlib.h>
- #include </usr/include/unistd.h>
- #include </usr/include/string.h>
- #include </usr/lib/gcc-lib/i486-pc-linux-gnu/3.2.3/include/stdarg.h>
- #include </usr/include/time.h>
char PROCNAME[128]
struct tm* CUR_TIME
ubs_table GLOBAL
int LOGLEVEL
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
void console_warning ( char* message )
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
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
This sets a global variable CUR_TIME to reflect the present time
void gettime ( void )
Prototyped in:
| include/ubs.h
|
Calls:
| localtime(), mktime(), time()
|
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
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
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
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
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)
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
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