- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

glog.h
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 // ===
20
21 #ifndef G_LOG_H
22 #define G_LOG_H
23
24 #include "gdef.h"
25 #include <sstream>
26 #include <string>
27
29 namespace G
30 {
31 class Log ;
32 }
33
50 class G::Log
51 {
52 public:
53 enum Severity { s_LogVerbose , s_LogSummary , s_Debug , s_Warning , s_Error , s_Assertion } ;
54
56 class Line
57 { public: const char * m_file ; int m_line ; Line( const char *file , int line ) : m_file(file) , m_line(line) {} } ;
58
59 Log( Severity , const char * file , int line ) ;
61
62 ~Log() ;
64
65 std::ostream & operator<<( const char * s ) ;
67
68 std::ostream & operator<<( const std::string & s ) ;
70
71 private:
72 void flush() ;
73 bool active() ;
74
75 private:
76 friend class G::Log::Line ;
77 Severity m_severity ;
78 std::ostringstream m_ss ;
79 const char * m_file ;
80 int m_line ;
81 } ;
82
91 #define G_LOG_OUTPUT( expr , severity ) do { G::Log(severity,__FILE__,__LINE__) << expr ; } while(0)
92 #if defined(G_WITH_DEBUG) || ( defined(_DEBUG) && ! defined(G_NO_DEBUG) )
93 #define G_DEBUG( expr ) G_LOG_OUTPUT( expr , G::Log::s_Debug )
94 #else
95 #define G_DEBUG( expr )
96 #endif
97 #if ! defined(G_NO_LOG)
98 #define G_LOG( expr ) G_LOG_OUTPUT( expr , G::Log::s_LogVerbose )
99 #else
100 #define G_LOG( expr )
101 #endif
102 #if ! defined(G_NO_LOG_S)
103 #define G_LOG_S( expr ) G_LOG_OUTPUT( expr , G::Log::s_LogSummary )
104 #else
105 #define G_LOG_S( expr )
106 #endif
107 #define G_WARNING( expr ) G_LOG_OUTPUT( expr , G::Log::s_Warning )
108 #define G_ERROR( expr ) G_LOG_OUTPUT( expr , G::Log::s_Error )
109
110 #endif
G::Log::Line
A class for adding line number information to the Log output.
Definition: glog.h:56
G::Log::s_Debug
Definition: glog.h:53
G::Log::s_LogVerbose
Definition: glog.h:53
G::Log::s_LogSummary
Definition: glog.h:53
G::Log::s_Error
Definition: glog.h:53
G::Log::Log
Log(Severity, const char *file, int line)
Constructor.
Definition: glog.cpp:25
G::Log::s_Assertion
Definition: glog.h:53
G::Log::s_Warning
Definition: glog.h:53
G
Low-level classes.
G::Log
A static class for doing iostream-based logging.
Definition: glog.h:50
G::Log::Severity
Severity
Definition: glog.h:53
G::Log::Line::m_line
int m_line
Definition: glog.h:57
G::Log::Line::m_file
const char * m_file
Definition: glog.h:57
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::Line::Line
Line(const char *file, int line)
Definition: glog.h:57
G::Log::~Log
~Log()
Destructor. Writes the accumulated string to the log output.
Definition: glog.cpp:32