libzypp  11.13.5
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 
17 #include "zypp/base/Logger.h"
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/Pathname.h"
20 
22 namespace zypp
23 {
24 
26  namespace log
27  {
28 
34  struct LineWriter
35  {
36  virtual void writeOut( const std::string & /*formated_r*/ )
37  {}
38  virtual ~LineWriter()
39  {}
40  };
41 
43  struct StreamLineWriter : public LineWriter
44  {
45  StreamLineWriter( std::ostream & str_r ) : _str( &str_r ) {}
46 
47  virtual void writeOut( const std::string & formated_r )
48  { (*_str) << formated_r << std::endl; }
49 
50  protected:
51  StreamLineWriter() : _str( 0 ) {}
52  std::ostream *_str;
53  };
54 
57  {
59  };
60 
63  {
65  };
66 
72  {
73  FileLineWriter( const Pathname & file_r, mode_t mode_r = 0 );
74  protected:
75  shared_ptr<void> _outs;
76  };
77 
79  } // namespace log
81 
82 
84  namespace base
85  {
86 
88  //
89  // CLASS NAME : LogControl
90  //
95  class LogControl
96  {
97  friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
98 
99  public:
102  { return LogControl(); }
103 
104 
107 
114  {
115  virtual std::string format( const std::string & /*group_r*/,
116  logger::LogLevel /*level_r*/,
117  const char * /*file_r*/,
118  const char * /*func_r*/,
119  int /*line_r*/,
120  const std::string & /*message_r*/ );
121  virtual ~LineFormater() {}
122  };
123 
124  public:
129  void setLineFormater( const shared_ptr<LineFormater> & formater_r );
130 
131  public:
138  void logfile( const Pathname & logfile_r );
139  void logfile( const Pathname & logfile_r, mode_t mode_r );
140 
142  void logNothing();
143 
145  void logToStdErr();
146 
147  public:
149  shared_ptr<LineWriter> getLineWriter() const;
150 
156  void setLineWriter( const shared_ptr<LineWriter> & writer_r );
157 
158  public:
161  {
162  TmpExcessive();
163  ~TmpExcessive();
164  };
165 
170  {
171  TmpLineWriter( const shared_ptr<LineWriter> & writer_r = shared_ptr<LineWriter>() )
173  { LogControl::instance().setLineWriter( writer_r ); }
174 
180  template<class _LineWriter>
181  TmpLineWriter( _LineWriter * _allocated_r )
183  { LogControl::instance().setLineWriter( shared_ptr<LineWriter>( _allocated_r ) ); }
184 
187 
188  private:
189  shared_ptr<LineWriter> _writer;
190  };
191 
192  private:
195  {}
196  };
198 
200  std::ostream & operator<<( std::ostream & str, const LogControl & obj );
201 
203  } // namespace base
206 } // namespace zypp
208 #endif // ZYPP_BASE_LOGCONTROL_H