- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

glog.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // glog.cpp
19 //
20
21 #include "gdef.h"
22 #include "glog.h"
23 #include "glogoutput.h"
24
25 G::Log::Log( Severity severity , const char * file , int line ) :
26 m_severity(severity) ,
27 m_file(file) ,
28 m_line(line)
29 {
30 }
31
32 G::Log::~Log()
33 {
34 try
35 {
36 flush() ;
37 }
38 catch(...)
39 {
40 }
41 }
42
43
44 bool G::Log::active()
45 {
46 LogOutput * output = G::LogOutput::instance() ;
47 if( output == NULL )
48 {
49 return false ;
50 }
51 else
52 {
53 // (enable it just to get the original state, then restore it)
54 bool a = output->enable(true) ;
55 output->enable(a) ;
56 return a ;
57 }
58 }
59
60 void G::Log::flush()
61 {
62 if( active() )
63 {
64 G::LogOutput::output( m_severity , m_file , m_line , m_ss.str() ) ;
65 }
66 }
67
68 std::ostream & G::Log::operator<<( const char * s )
69 {
70 s = s ? s : "" ;
71 return m_ss << s ;
72 }
73
74 std::ostream & G::Log::operator<<( const std::string & s )
75 {
76 return m_ss << s ;
77 }
78
G::LogOutput::enable
bool enable(bool enabled=true)
Enables or disables output. Returns the previous setting.
Definition: glogoutput.cpp:113
glog.h
G::LogOutput::instance
static LogOutput * instance()
Returns a pointer to the controlling LogOutput object.
Definition: glogoutput.cpp:108
glogoutput.h
G::Log::Log
Log(Severity, const char *file, int line)
Constructor.
Definition: glog.cpp:25
G::LogOutput::output
static void output(G::Log::Severity, const char *file, int line, const std::string &)
Generates output if there is an existing LogOutput object which is enabled.
Definition: glogoutput.cpp:120
G::Log::Severity
Severity
Definition: glog.h:53
G::LogOutput
Controls and implements low-level logging output, as used by the Log interface.
Definition: glogoutput.h:41
G::Log::operator<<
std::ostream & operator<<(const char *s)
Streams 's' and then returns a stream for streaming more stuff into.
Definition: glog.cpp:68
G::Log::~Log
~Log()
Destructor. Writes the accumulated string to the log output.
Definition: glog.cpp:32