fgms 0.11.8
The
FlightGear MultiPlayer Server
project
logstream.cxx
Go to the documentation of this file.
1 // Stream based logging mechanism.
2 //
3 // Written by Bernie Bright, 1998
4 //
5 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 // $Id: logstream.cxx,v 1.2 2010/02/15 08:04:17 oliver Exp $
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "logstream.hxx"
27 #include "stdio.h"
28 
30 
31 bool logbuf::console_enabled = false;
32 bool logbuf::logging_enabled = true;
33 #ifdef _MSC_VER
34 bool logbuf::has_console = true;
35 #endif
38 streambuf* logbuf::sbuf = NULL;
39 
41 {
42 }
43 
45 {
46  if ( sbuf )
47  {
48  sync();
49  }
50 }
51 
52 void
53 logbuf::set_sb ( streambuf* sb )
54 {
55  if ( sbuf )
56  {
57  sync();
58  }
59  sbuf = sb;
60 }
61 
62 void
64 {
65  logClass = c;
66  logPriority = p;
67 }
68 
69 void
71 {
72  logClass = c;
73 }
74 
75 void
77 {
78  int l = (int) logClass;
79  l |= c;
80  logClass = (sgDebugClass) l;
81 }
82 
83 void
85 {
86  int l = (int) logClass;
87  l &= ~c;
88  logClass = (sgDebugClass) l;
89 }
90 
93 {
94  return logClass;
95 }
96 
97 void
99 {
100  logPriority = p;
101 }
102 
105 {
106  return logPriority;
107 }
108 
109 
110 void
112 {
114 }
115 
116 void
118 {
120 }
121 
122 void
124 {
125  logbuf::set_log_level ( c, p );
126 }
127 
128 string
130 {
131  if ( with_date == false )
132  {
133  return "";
134  }
135  time_t date;
136  struct tm* tmr;
137  char buf[64];
138  if ( userdatestr )
139  {
140  string msg = ( *userdatestr ) ();
141  msg += " ";
142  return msg;
143  }
144  date = time ( 0 );
145  tmr = localtime ( &date );
146  sprintf ( buf, "%02d.%02d.%04d %02d:%02d:%02d ",
147  tmr->tm_mday,
148  tmr->tm_mon+1,
149  tmr->tm_year+1900,
150  tmr->tm_hour,
151  tmr->tm_min,
152  tmr->tm_sec );
153  return ( string ) buf;
154 }
155 
static void set_log_priority(sgDebugPriority p)
Set the logging priority.
Definition: logstream.cxx:98
void setLogLevels(sgDebugClass c, sgDebugPriority p)
Set the global log class and priority level.
Definition: logstream.cxx:123
static sgDebugPriority logPriority
Definition: logstream.hxx:193
static void set_log_level(sgDebugClass c, sgDebugPriority p)
Set the global logging level.
Definition: logstream.cxx:63
static void disable_log_class(sgDebugClass c)
disable logging of a single class
Definition: logstream.cxx:84
virtual int sync()
sync/flush
Definition: logstream.hxx:203
Stream based logging mechanism.
DATEFUNC userdatestr
Definition: logstream.hxx:354
bool with_date
Definition: logstream.hxx:351
sgDebugPriority
Define the possible logging priorities (and their order).
Definition: debug_types.h:24
void disable_log_class(sgDebugClass c)
disable logging of a single class
Definition: logstream.cxx:117
static sgDebugPriority get_log_priority()
Get the current logging priority.
Definition: logstream.cxx:104
logstream * global_logstream
Definition: logstream.cxx:29
void enable_log_class(sgDebugClass c)
enable logging of a single class
Definition: logstream.cxx:111
Class to manage the debug logging stream.
Definition: logstream.hxx:283
logbuf()
Constructor.
Definition: logstream.cxx:40
static void enable_log_class(sgDebugClass c)
enable logging of a single class
Definition: logstream.cxx:76
static sgDebugClass logClass
Definition: logstream.hxx:192
sgDebugClass
Define the possible classes/categories of logging messages.
Definition: debug_types.h:8
static void set_log_classes(sgDebugClass c)
Set the allowed logging classes.
Definition: logstream.cxx:70
static bool console_enabled
Definition: logstream.hxx:188
Informatory messages.
Definition: debug_types.h:32
void set_sb(streambuf *sb)
Set the stream buffer.
Definition: logstream.cxx:53
~logbuf()
Destructor.
Definition: logstream.cxx:44
string datestr(void)
Return a date as a string, standard format.
Definition: logstream.cxx:129
static sgDebugClass get_log_classes()
Get the logging classes currently enabled.
Definition: logstream.cxx:92
static streambuf * sbuf
The streambuf used for actual output. Defaults to cerr.rdbuf().
Definition: logstream.hxx:185
static bool logging_enabled
Definition: logstream.hxx:187