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 * Permission for logfiles is set to 0640 unless an explicit mode_t
83 * value is given. An empty pathname turns off logging. <tt>"-"</tt>
85 * \throw if \a logfile_r is not usable.
87 void logfile( const Pathname & logfile_r );
88 void logfile( const Pathname & logfile_r, mode_t mode_r );
90 /** Turn off logging. */
93 /** Log to std::err. */
96 /** Assign a LineWriter.
97 * If you want to log the (formated) loglines by yourself.
98 * NULL turns off logging (same as logNothing)
100 void setLineWriter( const shared_ptr<LineWriter> & writer_r );
103 /** Turn on excessive logging for the lifetime of this object.*/
110 /** Exchange LineWriter for the lifetime of this object. */
113 TmpLineWriter( const shared_ptr<LineWriter> & writer_r = shared_ptr<LineWriter>() );
116 shared_ptr<LineWriter> _writer;
120 /** Default ctor: Singleton */
124 ///////////////////////////////////////////////////////////////////
126 /** \relates LogControl Stream output */
127 std::ostream & operator<<( std::ostream & str, const LogControl & obj );
129 /////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////
132 /////////////////////////////////////////////////////////////////
134 ///////////////////////////////////////////////////////////////////
135 #endif // ZYPP_BASE_LOGCONTROL_H