paludis Version 3.0.2
The one true package mangler
log.hh
Go to the documentation of this file.
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
5 *
6 * This file is part of the Paludis package manager. Paludis is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU General
8 * Public License version 2, as published by the Free Software Foundation.
9 *
10 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifndef PALUDIS_GUARD_PALUDIS_LOG_HH
21#define PALUDIS_GUARD_PALUDIS_LOG_HH 1
22
25#include <paludis/util/pimp.hh>
26#include <iosfwd>
27#include <string>
28
29/** \file
30 * Declarations for Log and related classes.
31 *
32 * \ingroup g_log
33 *
34 * \section Examples
35 *
36 * - None at this time.
37 */
38
39namespace paludis
40{
41#include <paludis/util/log-se.hh>
42
44
45 /**
46 * Singleton class that handles log messages.
47 *
48 * \ingroup g_log
49 */
50 class PALUDIS_VISIBLE Log :
51 public Singleton<Log>
52 {
53 friend class Singleton<Log>;
54 friend class LogMessageHandler;
55
56 private:
57 Pimp<Log> _imp;
58
59 Log();
60
61 void _message(const std::string & id, const LogLevel, const LogContext, const std::string &);
62
63 public:
64 /**
65 * Destructor, to be called only by our InstantiationPolicy.
66 */
68
69 /**
70 * Only display messages of at least this level.
71 */
72 void set_log_level(const LogLevel);
73
74 /**
75 * Fetch the current log level.
76 */
77 LogLevel log_level() const
78 PALUDIS_ATTRIBUTE((warn_unused_result));
79
80 /**
81 * Log a message.
82 *
83 * The return value can be appended to using
84 * LogMessageHandler::operator<<(). When the return value is
85 * destroyed (that is to say, at the end of the statement), the log
86 * message is written.
87 */
88 LogMessageHandler message(const std::string & id,
89 const LogLevel, const LogContext) PALUDIS_ATTRIBUTE((warn_unused_result));
90
91 /**
92 * Change the log stream.
93 */
94 void set_log_stream(std::ostream * const);
95
96 /**
97 * Set our program name.
98 */
99 void set_program_name(const std::string &);
100 };
101
102 /**
103 * Used by Log::message().
104 *
105 * \see Log
106 * \ingroup g_log
107 */
108 class PALUDIS_VISIBLE LogMessageHandler
109 {
110 friend LogMessageHandler Log::message(const std::string &, const LogLevel, const LogContext);
111
112 private:
113 Log * _log;
114 std::string _id;
115 std::string _message;
116 LogLevel _log_level;
117 LogContext _log_context;
118
119 LogMessageHandler(const LogMessageHandler &);
120 LogMessageHandler(Log * const, const std::string &, const LogLevel, const LogContext);
121 void operator= (const LogMessageHandler &);
122
123 void _append(const std::string & s);
124
125 public:
126 ///\name Basic operations
127 ///\{
128
129 ~LogMessageHandler();
130
131 ///\}
132
133 /**
134 * Append some text to our message.
135 */
136 template <typename T_>
137 LogMessageHandler &
138 operator<< (const T_ & t)
139 {
140 _append(stringify(t));
141 return *this;
142 }
143 };
144
145 extern template class Pimp<Log>;
146}
147
148#endif
Definition log.hh:109
Definition log.hh:52
LogLevel log_level() const PALUDIS_ATTRIBUTE((warn_unused_result))
void set_log_stream(std::ostream *const)
void set_program_name(const std::string &)
void set_log_level(const LogLevel)
LogMessageHandler message(const std::string &id, const LogLevel, const LogContext) PALUDIS_ATTRIBUTE((warn_unused_result))
Definition pimp.hh:52
std::string stringify(const T_ &item)
Definition stringify.hh:166
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24