E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

glog.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 bool G::Log::at( Severity s )
44 {
45 LogOutput * output = G::LogOutput::instance() ;
46 return output != nullptr && output->at(s) ;
47 }
48
49 bool G::Log::at( Severity s , const char * group )
50 {
51 LogOutput * output = G::LogOutput::instance() ;
52 return output && group && *group ? output->at(s,group) : false ;
53 }
54
55 bool G::Log::active()
56 {
57 LogOutput * output = G::LogOutput::instance() ;
58 if( output == nullptr )
59 {
60 return false ;
61 }
62 else
63 {
64 // (enable it just to get the original state, then restore it)
65 bool a = output->enable(true) ;
66 output->enable(a) ;
67 return a ;
68 }
69 }
70
71 void G::Log::flush()
72 {
73 if( active() )
74 {
75 G::LogOutput::output( m_severity , m_file , m_line , m_ss.str() ) ;
76 }
77 }
78
79 std::ostream & G::Log::operator<<( const char * s )
80 {
81 s = s ? s : "" ;
82 return m_ss << s ;
83 }
84
85 std::ostream & G::Log::operator<<( const std::string & s )
86 {
87 return m_ss << s ;
88 }
89
90 /// \file glog.cpp
G::LogOutput::enable
bool enable(bool enabled=true)
Enables or disables output. Returns the previous setting.
Definition: glogoutput.cpp:119
glog.h
G::Log::at
static bool at(Severity)
Returns true if G::LogOutput::output() would log at the given level.
Definition: glog.cpp:43
G::LogOutput::instance
static LogOutput * instance()
Returns a pointer to the controlling LogOutput object.
Definition: glogoutput.cpp:114
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:136
G::LogOutput::at
bool at(G::Log::Severity) const
Returns true if logging should occur for the given severity level.
Definition: glogoutput.cpp:142
G::LogOutput
Controls and implements low-level logging output, as used by the Log interface.
Definition: glogoutput.h:42
G::Log::operator<<
std::ostream & operator<<(const char *s)
Streams 's' and then returns a stream for streaming more stuff into.
Definition: glog.cpp:79
G::Log::~Log
~Log()
Destructor. Writes the accumulated string to the log output.
Definition: glog.cpp:32