Go to the documentation of this file.00001
00007
00008
00009
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <stdarg.h>
00014
00015 #include "log.h"
00016
00017 static char * _GS_DEFAULT_LOG_EVENT = NULL;
00018 static char * _GS_DEFAULT_LOG_IDENT = NULL;
00019
00020
00021
00022
00023
00035 int
00036 gs_log_init(const char *ident, int option, int facility, const char *default_event)
00037 {
00038 fprintf(stderr,"Initializing logging %s %s \n", ident, default_event);
00039 _GS_DEFAULT_LOG_EVENT = strdup(default_event);
00040 _GS_DEFAULT_LOG_IDENT = strdup(ident);
00041 fprintf(stderr,"Set logging %s %s \n", _GS_DEFAULT_LOG_IDENT, _GS_DEFAULT_LOG_EVENT);
00042
00043 atexit((void (*)())gs_log_finalize);
00044 return 0;
00045 }
00046
00061 int
00062 gs_log_write(const char* file, const int line, const char* function, int level, const char* event, const char* format, ...)
00063 {
00064 va_list argptr;
00065
00066 if (event == NULL) {
00067 fprintf(stderr, "Received NULL event, default %s\n", _GS_DEFAULT_LOG_EVENT);
00068 event = _GS_DEFAULT_LOG_EVENT;
00069 }
00070 fprintf(stderr,"%s:%d [%s] %d %s", file,line,function,level,event);
00071
00072 va_start(argptr, format);
00073 vfprintf(stderr,format, argptr);
00074 fflush(stderr);
00075
00076 return 0;
00077 }
00078
00085 int
00086 gs_log_finalize()
00087 {
00088 if(_GS_DEFAULT_LOG_EVENT)
00089 free(_GS_DEFAULT_LOG_EVENT);
00090 _GS_DEFAULT_LOG_EVENT = NULL;
00091
00092 if(_GS_DEFAULT_LOG_IDENT)
00093 free(_GS_DEFAULT_LOG_IDENT);
00094 _GS_DEFAULT_LOG_IDENT = NULL;
00095
00096 return 0;
00097 }