E-MailRelay
glog.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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/// \file glog.cpp
19///
20
21#include "gdef.h"
22#include "glog.h"
23#include "glogoutput.h"
24
25G::Log::Log( Severity severity , const char * file , int line ) :
26 m_severity(severity) ,
27 m_file(file) ,
28 m_line(line) ,
29 m_ostream(LogOutput::start(m_severity,m_file,m_line))
30{
31}
32
34{
35 try
36 {
37 LogOutput::output( m_ostream ) ;
38 }
39 catch(...)
40 {
41 }
42}
43
44bool G::Log::at( Severity s )
45{
46 const LogOutput * log_output = LogOutput::instance() ;
47 return log_output && log_output->at( s ) ;
48}
49
50std::ostream & G::Log::operator<<( const char * s )
51{
52 s = s ? s : "" ;
53 return m_ostream << s ;
54}
55
56std::ostream & G::Log::operator<<( const std::string & s )
57{
58 return m_ostream << s ;
59}
60
Controls and implements low-level logging output, as used by G::Log.
Definition: glogoutput.h:50
bool at(Log::Severity) const noexcept
Returns true if logging should occur for the given severity level.
Definition: glogoutput.cpp:149
static void output(std::ostream &)
Emits the current log line (see start()).
Definition: glogoutput.cpp:169
static LogOutput * instance() noexcept
Returns a pointer to the controlling LogOutput object.
Definition: glogoutput.cpp:128
~Log()
Destructor. Writes the accumulated string to the log output.
Definition: glog.cpp:33
std::ostream & operator<<(const char *s)
Streams 's' and then returns a stream for streaming more stuff into.
Definition: glog.cpp:50
Log(Severity, const char *file, int line)
Constructor.
Definition: glog.cpp:25
static bool at(Severity)
Returns true if G::LogOutput::output() would log at the given level.
Definition: glog.cpp:44