Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

logger.c

00001 /***************************************************************************
00002  * CVSID: $Id: logger.c,v 1.3 2004/03/03 17:56:56 david Exp $
00003  *
00004  * logger.c : Logging 
00005  *
00006  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
00007  *
00008  * Licensed under the Academic Free License version 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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:        /* explicit fallthrough */
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 

Generated on Thu Mar 11 21:32:23 2004 for HAL by doxygen 1.3.6-20040222