]> git.mxchange.org Git - simgear.git/blob - simgear/debug/logstream.cxx
remove redundant #defines (they are already in compiler.h)
[simgear.git] / simgear / debug / logstream.cxx
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$
22
23 #include <iostream>
24
25 #include "logstream.hxx"
26
27 logstream *logstream::global_logstream = 0;
28
29 bool            logbuf::logging_enabled = true;
30 #ifdef _MSC_VER
31    bool         logbuf::has_console = true;
32 #endif
33 sgDebugClass    logbuf::logClass        = SG_NONE;
34 sgDebugPriority logbuf::logPriority     = SG_INFO;
35 streambuf*      logbuf::sbuf            = NULL;
36
37 logbuf::logbuf()
38 {
39 //     if ( sbuf == NULL )
40 //      sbuf = cerr.rdbuf();
41 }
42
43 logbuf::~logbuf()
44 {
45     if ( sbuf )
46             sync();
47 }
48
49 void
50 logbuf::set_sb( streambuf* sb )
51 {
52     if ( sbuf )
53             sync();
54
55     sbuf = sb;
56 }
57
58 void
59 logbuf::set_log_level( sgDebugClass c, sgDebugPriority p )
60 {
61     logClass = c;
62     logPriority = p;
63 }
64
65 void
66 logbuf::set_log_classes (sgDebugClass c)
67 {
68     logClass = c;
69 }
70
71 sgDebugClass
72 logbuf::get_log_classes ()
73 {
74     return logClass;
75 }
76
77 void
78 logbuf::set_log_priority (sgDebugPriority p)
79 {
80     logPriority = p;
81 }
82
83 sgDebugPriority
84 logbuf::get_log_priority ()
85 {
86     return logPriority;
87 }
88
89 void
90 logstream::setLogLevels( sgDebugClass c, sgDebugPriority p )
91 {
92     logbuf::set_log_level( c, p );
93 }
94
95 void
96 logstream::initGlobalLogstream()
97 {
98     // Force initialization of cerr.
99     static std::ios_base::Init initializer;
100     // XXX Is the following still necessary?
101 #ifdef __APPLE__
102     /**
103      * There appears to be a bug in the C++ runtime in Mac OS X that
104      * will crash if certain funtions are called (in this case
105      * cerr.rdbuf()) during static initialization of a class. This
106      * print statement is hack to kick the library in the pants so it
107      * won't crash when cerr.rdbuf() is first called -DW 
108      **/
109     std::cout << "Using Mac OS X hack for initializing C++ stdio..."
110               << std::endl;
111 #endif
112     global_logstream = new logstream(std::cerr);
113 }