libzypp 17.28.8
LogControl.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_BASE_LOGCONTROL_H
13#define ZYPP_BASE_LOGCONTROL_H
14
15#include <iosfwd>
16#include <ostream> //for std::endl
17
18#include <zypp-core/base/Logger.h>
19#include <zypp-core/base/PtrTypes.h>
20#include <zypp-core/Pathname.h>
21
23namespace zypp
24{
25
27 namespace log
28 {
29
35 struct LineWriter
36 {
37 virtual void writeOut( const std::string & /*formated_r*/ )
38 {}
39 virtual ~LineWriter()
40 {}
41 };
42
44 struct StreamLineWriter : public LineWriter
45 {
46 StreamLineWriter( std::ostream & str_r ) : _str( &str_r ) {}
47
48 virtual void writeOut( const std::string & formated_r )
49 { (*_str) << formated_r << std::endl; }
50
51 protected:
52 StreamLineWriter() : _str( 0 ) {}
53 std::ostream *_str;
54 };
55
57 struct StdoutLineWriter : public StreamLineWriter
58 {
60 };
61
63 struct StderrLineWriter : public StreamLineWriter
64 {
66 };
67
72 struct FileLineWriter : public StreamLineWriter
73 {
74 FileLineWriter( const Pathname & file_r, mode_t mode_r = 0 );
75 protected:
77 };
78
80 } // namespace log
82
83
85 namespace base
86 {
87
89 //
90 // CLASS NAME : LogControl
91 //
96 class LogControl
97 {
98 friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
99
100 public:
102 static LogControl instance()
103 { return LogControl(); }
104
105
107 typedef log::LineWriter LineWriter;
108
114 struct LineFormater
115 {
116 virtual std::string format( const std::string & /*group_r*/,
117 logger::LogLevel /*level_r*/,
118 const char * /*file_r*/,
119 const char * /*func_r*/,
120 int /*line_r*/,
121 const std::string & /*message_r*/ );
122 virtual ~LineFormater() {}
123 };
124
125 public:
130 void setLineFormater( const shared_ptr<LineFormater> & formater_r );
131
132 public:
139 void logfile( const Pathname & logfile_r );
140 void logfile( const Pathname & logfile_r, mode_t mode_r );
141
143 void logNothing();
144
146 void logToStdErr();
147
149 void emergencyShutdown();
150
156 static void notifyFork();
157
158 public:
161
167 void setLineWriter( const shared_ptr<LineWriter> & writer_r );
168
169 public:
171 struct TmpExcessive
172 {
173 TmpExcessive();
175 };
176
180 struct TmpLineWriter
181 {
184 { LogControl::instance().setLineWriter( writer_r ); }
185
191 template<class TLineWriter>
192 TmpLineWriter( TLineWriter * _allocated_r )
195
198
199 private:
201 };
202
203 private:
205 LogControl()
206 {}
207 };
209
211 std::ostream & operator<<( std::ostream & str, const LogControl & obj );
212
214 } // namespace base
217} // namespace zypp
219#endif // ZYPP_BASE_LOGCONTROL_H
friend std::ostream & operator<<(std::ostream &str, const LogControl &obj)
Definition: LogControl.cc:905
LogControl()
Default ctor: Singleton.
Definition: LogControl.h:205
shared_ptr< LineWriter > getLineWriter() const
Get the current LineWriter.
Definition: LogControl.cc:829
void setLineWriter(const shared_ptr< LineWriter > &writer_r)
Assign a LineWriter.
Definition: LogControl.cc:838
void emergencyShutdown()
will cause the log thread to exit and flush all sockets
Definition: LogControl.cc:870
void logToStdErr()
Log to std::err.
Definition: LogControl.cc:862
void logNothing()
Turn off logging.
Definition: LogControl.cc:854
static void notifyFork()
This will completely disable logging, its supposed to be called in the child process after fork() was...
Definition: LogControl.cc:875
void setLineFormater(const shared_ptr< LineFormater > &formater_r)
Assign a LineFormater.
Definition: LogControl.cc:846
static LogControl instance()
Singleton access.
Definition: LogControl.h:102
void logfile(const Pathname &logfile_r)
Set path for the logfile.
Definition: LogControl.cc:811
log::LineWriter LineWriter
Definition: LogControl.h:107
String related utilities and Regular expression matching.
LogLevel
Definition of log levels.
Definition: Logger.h:145
std::ostream & operator<<(std::ostream &str, const Flags< TEnum > &obj)
Definition: Flags.h:166
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
virtual std::string format(const std::string &, logger::LogLevel, const char *, const char *, int, const std::string &)
Definition: LogControl.cc:772
TmpLineWriter(const shared_ptr< LineWriter > &writer_r=shared_ptr< LineWriter >())
Definition: LogControl.h:182
shared_ptr< LineWriter > _writer
Definition: LogControl.h:200
shared_ptr< void > _outs
Definition: LogControl.h:76
FileLineWriter(const Pathname &file_r, mode_t mode_r=0)
Definition: LogControl.cc:359
virtual void writeOut(const std::string &)
Definition: LogControl.h:37
virtual ~LineWriter()
Definition: LogControl.h:39
virtual void writeOut(const std::string &formated_r)
Definition: LogControl.h:48