- Updated LogControl. setLineWriter allows to define a consumer
[platform/upstream/libzypp.git] / zypp / base / LogControl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/LogControl.h
10  *
11 */
12 #ifndef ZYPP_BASE_LOGCONTROL_H
13 #define ZYPP_BASE_LOGCONTROL_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/Pathname.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   namespace base
25   { /////////////////////////////////////////////////////////////////
26
27     ///////////////////////////////////////////////////////////////////
28     //
29     //  CLASS NAME : LogControl
30     //
31     /** Maintain logfile related options.
32      * \note A Singleton using a Singleton implementation class,
33      * that's why there is no _pimpl like in other classes.
34     */
35     class LogControl
36     {
37       friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
38
39     public:
40       /** Singleton access. */
41       static LogControl instance()
42       { return LogControl(); }
43
44
45       /** If you want to log the (formated) loglines by yourself,
46        * derive from this, and overload \c writeOut. */
47       struct LineWriter
48       {
49         virtual void writeOut( const std::string & /*formated_r*/ )
50         {}
51
52         virtual ~LineWriter() {}
53       };
54
55     public:
56       /** Set path for the logfile.
57        * An emty pathname for std::err.
58        * \throw if \a logfile_r is not usable.
59       */
60       void logfile( const Pathname & logfile_r );
61
62       void logNothing();
63
64       void logToStdErr();
65
66       /** Assign a LineWriter.
67        * If you want to log the (formated) loglines by yourself. */
68       void setLineWriter( const shared_ptr<LogControl::LineWriter> & writer_r );
69
70     public:
71       /** Turn on excessive logging for the lifetime of this object.*/
72       struct TmpExcessive
73       {
74         TmpExcessive();
75         ~TmpExcessive();
76       };
77
78     private:
79       /** Default ctor: Singleton */
80       LogControl()
81       {}
82     };
83     ///////////////////////////////////////////////////////////////////
84
85     /** \relates LogControl Stream output */
86     std::ostream & operator<<( std::ostream & str, const LogControl & obj );
87
88     /////////////////////////////////////////////////////////////////
89   } // namespace base
90   ///////////////////////////////////////////////////////////////////
91   /////////////////////////////////////////////////////////////////
92 } // namespace zypp
93 ///////////////////////////////////////////////////////////////////
94 #endif // ZYPP_BASE_LOGCONTROL_H