libzypp 17.37.17
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
20#include <zypp-core/Pathname.h>
21
23namespace zypp
24{
25
27 namespace log
28 {
29
36 {
37 virtual void writeOut( const std::string & /*formated_r*/ )
38 {}
39 virtual ~LineWriter()
40 {}
41 };
42
45 {
46 StreamLineWriter( std::ostream & str_r ) : _str( &str_r ) {}
47
48 void writeOut( const std::string & formated_r ) override
49 { (*_str) << formated_r << std::endl; }
50
51 protected:
53 std::ostream *_str;
54 };
55
58 {
60 };
61
64 {
66 };
67
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 //
97 {
98 friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
99
100 public:
103 { return LogControl(); }
104
105
108
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
137 void enableLogForwardingMode ( bool enable = true );
138
139 public:
146 void logfile( const Pathname & logfile_r );
147 void logfile( const Pathname & logfile_r, mode_t mode_r );
148
150 void logNothing();
151
153 void logToStdErr();
154
156 void emergencyShutdown();
157
163 static void notifyFork();
164
166 void logRawLine ( std::string &&line );
167
168 public:
170 shared_ptr<LineWriter> getLineWriter() const;
171
177 void setLineWriter( const shared_ptr<LineWriter> & writer_r );
178
179 public:
182 {
183 TmpExcessive();
185 };
186
191 {
194 { LogControl::instance().setLineWriter( writer_r ); }
195
201 template<class TLineWriter>
202 TmpLineWriter( TLineWriter * _allocated_r )
204 { LogControl::instance().setLineWriter( shared_ptr<LineWriter>( _allocated_r ) ); }
205
207 { LogControl::instance().setLineWriter( _writer ); }
208
209 private:
211 };
212
213 private:
216 {}
217 };
218
219
221 std::ostream & operator<<( std::ostream & str, const LogControl & obj ) ZYPP_API;
222
224 } // namespace base
227} // namespace zypp
229#endif // ZYPP_BASE_LOGCONTROL_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
LogControl()
Default ctor: Singleton.
Definition LogControl.h:215
shared_ptr< LineWriter > getLineWriter() const
Get the current LineWriter.
log::LineWriter LineWriter
Definition LogControl.h:107
static LogControl instance()
Singleton access.
Definition LogControl.h:102
String related utilities and Regular expression matching.
LogLevel
Definition of log levels.
Definition Logger.h:156
std::ostream & operator<<(std::ostream &str, const Flags< TEnum > &obj)
Definition Flags.h:166
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
If you want to format loglines by yourself, derive from this, and overload format.
Definition LogControl.h:115
virtual std::string format(const std::string &, logger::LogLevel, const char *, const char *, int, const std::string &)
TmpLineWriter(const shared_ptr< LineWriter > &writer_r=shared_ptr< LineWriter >())
Definition LogControl.h:192
shared_ptr< LineWriter > _writer
Definition LogControl.h:210
TmpLineWriter(TLineWriter *_allocated_r)
Convenience ctor taking over ownership of an allocated LineWriter.
Definition LogControl.h:202
shared_ptr< void > _outs
Definition LogControl.h:76
FileLineWriter(const Pathname &file_r, mode_t mode_r=0)
If you want to log the (formated) loglines by yourself, derive from this, and overload writeOut.
Definition LogControl.h:36
virtual void writeOut(const std::string &)
Definition LogControl.h:37
StreamLineWriter(std::ostream &str_r)
Definition LogControl.h:46
void writeOut(const std::string &formated_r) override
Definition LogControl.h:48