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

logger.c

00001 /***************************************************************************
00002  * CVSID: $Id: logger.c,v 1.2 2003/12/21 17:26:12 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 logger_init()
00054 {
00055 }
00056 
00064 void logger_setup(int _priority, const char* _file, int _line, 
00065                   const char* _function)
00066 {
00067     priority = _priority;
00068     file = _file;
00069     line = _line;
00070     function = _function;
00071 }
00072 
00078 void logger_emit(const char* format,...)
00079 {
00080     va_list args;
00081     char buf[512];
00082     char* pri;
00083 
00084     va_start(args, format);
00085     vsnprintf(buf, 512, format, args);
00086 
00087     switch( priority )
00088     {
00089     case HAL_LOGPRI_TRACE:   pri="[T]"; break;
00090     case HAL_LOGPRI_DEBUG:   pri="[D]"; break;
00091     case HAL_LOGPRI_INFO:    pri="[I]"; break;
00092     case HAL_LOGPRI_WARNING: pri="[W]"; break;
00093     default: /* explicit fallthrough */
00094     case HAL_LOGPRI_ERROR:   pri="[E]"; break;
00095     }
00096 
00098     if( priority!=HAL_LOGPRI_TRACE )
00099         fprintf(stderr, "%s %s:%d %s() : %s\n", 
00100                 pri, file, line, function, buf);
00101 
00102     va_end(args);
00103 }
00104 
00105 

Generated on Sat Feb 7 22:11:48 2004 for HAL by doxygen 1.3.5