00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <stdarg.h>
00034
00035 #include "logger.h"
00036
00045 static int priority;
00046 static const char *file;
00047 static int line;
00048 static const char *function;
00049
00053 void
00054 logger_init ()
00055 {
00056 }
00057
00065 void
00066 logger_setup (int _priority, const char *_file, int _line,
00067 const char *_function)
00068 {
00069 priority = _priority;
00070 file = _file;
00071 line = _line;
00072 function = _function;
00073 }
00074
00080 void
00081 logger_emit (const char *format, ...)
00082 {
00083 va_list args;
00084 char buf[512];
00085 char *pri;
00086
00087 va_start (args, format);
00088 vsnprintf (buf, 512, format, args);
00089
00090 switch (priority) {
00091 case HAL_LOGPRI_TRACE:
00092 pri = "[T]";
00093 break;
00094 case HAL_LOGPRI_DEBUG:
00095 pri = "[D]";
00096 break;
00097 case HAL_LOGPRI_INFO:
00098 pri = "[I]";
00099 break;
00100 case HAL_LOGPRI_WARNING:
00101 pri = "[W]";
00102 break;
00103 default:
00104 case HAL_LOGPRI_ERROR:
00105 pri = "[E]";
00106 break;
00107 }
00108
00110 if (priority != HAL_LOGPRI_TRACE)
00111 fprintf (stderr, "%s %s:%d %s() : %s\n",
00112 pri, file, line, function, buf);
00113
00114 va_end (args);
00115 }
00116
00117