1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/LogControl.h
12 #ifndef ZYPP_BASE_LOGCONTROL_H
13 #define ZYPP_BASE_LOGCONTROL_H
17 #include "zypp/base/Logger.h"
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/Pathname.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 // CLASS NAME : LogControl
32 /** Maintain logfile related options.
33 * \note A Singleton using a Singleton implementation class,
34 * that's why there is no _pimpl like in other classes.
38 friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
41 /** Singleton access. */
42 static LogControl instance()
43 { return LogControl(); }
46 /** If you want to log the (formated) loglines by yourself,
47 * derive from this, and overload \c writeOut.
48 * Expect \a formated_r to be a formated log line without trailing \c NL.
49 * Ready to be written to the log.
53 virtual void writeOut( const std::string & /*formated_r*/ )
55 virtual ~LineWriter() {}
58 /** If you want to format loglines by yourself,
59 * derive from this, and overload \c format.
60 * Return a formated logline without trailing \c NL.
61 * Ready to be written to the log.
65 virtual std::string format( const std::string & /*group_r*/,
66 logger::LogLevel /*level_r*/,
67 const char * /*file_r*/,
68 const char * /*func_r*/,
70 const std::string & /*message_r*/ );
71 virtual ~LineFormater() {}
75 /** Assign a LineFormater.
76 * If you want to format loglines by yourself. NULL installs the
79 void setLineFormater( const shared_ptr<LineFormater> & formater_r );
81 /** Set path for the logfile.
82 * An empty pathname turns off logging.
83 * <tt>"-"</tt> logs to std::err.
84 * \throw if \a logfile_r is not usable.
86 void logfile( const Pathname & logfile_r );
88 /** Turn off logging. */
91 /** Log to std::err. */
94 /** Assign a LineWriter.
95 * If you want to log the (formated) loglines by yourself.
96 * NULL turns off logging (same as logNothing)
98 void setLineWriter( const shared_ptr<LineWriter> & writer_r );
101 /** Turn on excessive logging for the lifetime of this object.*/
108 /** Exchange LineWriter for the lifetime of this object. */
111 TmpLineWriter( const shared_ptr<LineWriter> & writer_r = shared_ptr<LineWriter>() );
114 shared_ptr<LineWriter> _writer;
118 /** Default ctor: Singleton */
122 ///////////////////////////////////////////////////////////////////
124 /** \relates LogControl Stream output */
125 std::ostream & operator<<( std::ostream & str, const LogControl & obj );
127 /////////////////////////////////////////////////////////////////
129 ///////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////
133 #endif // ZYPP_BASE_LOGCONTROL_H