00001 // Stream based logging mechanism. 00002 // 00003 // Written by Bernie Bright, 1998 00004 // 00005 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // Library General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 // 00021 // $Id: logstream_8cxx_source.html,v 1.3 2010/02/23 22:10:14 curt Exp $ 00022 00023 #include <iostream> 00024 00025 #include "logstream.hxx" 00026 00027 logstream *logstream::global_logstream = 0; 00028 00029 bool logbuf::logging_enabled = true; 00030 #ifdef _WIN32 00031 bool logbuf::has_console = true; 00032 #endif 00033 sgDebugClass logbuf::logClass = SG_NONE; 00034 sgDebugPriority logbuf::logPriority = SG_INFO; 00035 streambuf* logbuf::sbuf = NULL; 00036 00037 namespace { 00038 struct ignore_me 00039 { 00040 ignore_me() 00041 { 00042 logstream::initGlobalLogstream(); 00043 } 00044 }; 00045 static ignore_me im; 00046 } 00047 00048 logbuf::logbuf() 00049 { 00050 // if ( sbuf == NULL ) 00051 // sbuf = cerr.rdbuf(); 00052 } 00053 00054 logbuf::~logbuf() 00055 { 00056 if ( sbuf ) 00057 sync(); 00058 } 00059 00060 void 00061 logbuf::set_sb( streambuf* sb ) 00062 { 00063 if ( sbuf ) 00064 sync(); 00065 00066 sbuf = sb; 00067 } 00068 00069 void 00070 logbuf::set_log_level( sgDebugClass c, sgDebugPriority p ) 00071 { 00072 logClass = c; 00073 logPriority = p; 00074 } 00075 00076 void 00077 logbuf::set_log_classes (sgDebugClass c) 00078 { 00079 logClass = c; 00080 } 00081 00082 sgDebugClass 00083 logbuf::get_log_classes () 00084 { 00085 return logClass; 00086 } 00087 00088 void 00089 logbuf::set_log_priority (sgDebugPriority p) 00090 { 00091 logPriority = p; 00092 } 00093 00094 sgDebugPriority 00095 logbuf::get_log_priority () 00096 { 00097 return logPriority; 00098 } 00099 00100 void 00101 logstream::setLogLevels( sgDebugClass c, sgDebugPriority p ) 00102 { 00103 logbuf::set_log_level( c, p ); 00104 } 00105 00106 logstream * 00107 logstream::initGlobalLogstream() 00108 { 00109 // Force initialization of cerr. 00110 static std::ios_base::Init initializer; 00111 if( !global_logstream ) 00112 global_logstream = new logstream(std::cerr); 00113 return global_logstream; 00114 }