Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

o_logging.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:05 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: o_logging.cpp,v 1.1.1.1 2002/12/07 19:02:05 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: o_logging.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:05  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00040 #include            <stdarg.h>
00041 #include            "omicron/internal.h"
00042  
00043 /**************************************************************************** 
00044  **************************************************************************** 
00045  * VARIABLES **************************************************************** 
00046  **************************************************************************** 
00047  ****************************************************************************/ 
00048  
00049 static FILE         *_logfile      = NULL; 
00050 static bool         _critical_done = false;
00051  
00052  
00053 /**************************************************************************** 
00054  **************************************************************************** 
00055  * LOGGING ROUTINES ********************************************************* 
00056  **************************************************************************** 
00057  ****************************************************************************/ 
00058  
00059  
00060  
00061 /**************************************************************************** 
00062  * _log_init                                             initialize logging * 
00063  ****************************************************************************/ 
00064 void _log_init() 
00065 { 
00066     if (gv.init.nolog)
00067         _logfile = NULL;
00068     else
00069         _logfile = fopen("debug.log", "w+"); 
00070         
00071     _critical_done = false;
00072 } // _log_init 
00073  
00074  
00075  
00076 /**************************************************************************** 
00077  * _log_deinit                                         deinitialize logging * 
00078  ****************************************************************************/ 
00079 void _log_deinit() 
00080 { 
00081     if (_logfile)
00082         fclose(_logfile); 
00083 } // _log_deinit 
00084  
00085 extern void _deinit(); 
00086  
00087 /**************************************************************************** 
00088  * _log_printf                                   prints a line into the log * 
00089  ****************************************************************************/ 
00090 void _log_printf 
00091 ( 
00092     sshort          level, 
00093     char            *fmt, 
00094     ... 
00095 ) 
00096 { 
00097     if (!_logfile)
00098         return;
00099 
00100     if (level<gv.debuglevel) 
00101       return; 
00102  
00103     va_list     argptr; 
00104     char        text[2048]; 
00105  
00106     va_start (argptr, fmt); 
00107     vsprintf (text, fmt, argptr); 
00108     va_end (argptr); 
00109  
00110     if (_logfile) 
00111     { 
00112         switch(level) 
00113         { 
00114             case MSG_DEBUG3: 
00115             case MSG_DEBUG2: 
00116             case MSG_DEBUG: 
00117                 fprintf( _logfile, " DD "); 
00118                 break; 
00119  
00120             case MSG_NORMAL: 
00121                 fprintf( _logfile, " -- "); 
00122                 break; 
00123  
00124             case MSG_WARNING: 
00125                 fprintf( _logfile, " WW "); 
00126                 break; 
00127              
00128             case MSG_ERROR: 
00129                 fprintf( _logfile, " EE "); 
00130                 break; 
00131              
00132             case MSG_CRITICAL: 
00133                 fprintf( _logfile, " !! "); 
00134                 break; 
00135         } 
00136  
00137         fprintf( _logfile, " - %s\n", text ); 
00138         fflush(_logfile); 
00139     } 
00140     printf( "%s\n", text ); 
00141 
00142     if (level == MSG_CRITICAL && !_critical_done)
00143     {
00144         _critical_done = true;
00145         _deinit();
00146 
00147 #if defined(WIN32) 
00148 
00149         MessageBeep(MB_ICONEXCLAMATION);
00150         MessageBox(NULL, text, "Critical Error", MB_ICONERROR);
00151 
00152 #endif
00153       exit(0);
00154     }
00155 } // _log_printf 
00156 

Generated on Wed Dec 18 15:48:47 2002 for omicron engine by doxygen1.2.18