]>
Dogcows Code - chaz/yoink/blob - src/moof/log.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
17 * Functions related to logging the process.
18 * The logging functions are log_error(), log_warning(), and log_info(),
19 * listed from most critical to least critical.
22 #include <cstdlib> // exit
33 * A class for handling a log priority. There are two ways to log
34 * messages: by treating a log object as a function whose parameters are
35 * printed with default spacing, or by treating a log object as an output
36 * stream. Either way, any object can be printed to the log as long as
37 * there is an override for the ostream insertion operator.
44 * A type for the level or priority of a log message.
48 none
= 0, ///< Disable all logging.
49 error
= 1, ///< Log only errors.
50 warning
= 2, ///< Log warnings and errors.
51 info
= 3, ///< Log everything.
56 * Set the lowest-priority log message that will be outputted to the
57 * log. Any logging with a lower priority will be ignored.
58 * \param level The log level.
60 static void level(level level
);
63 * Get the current lowest-priority log level. If unchanged, the
64 * default level is info.
65 * \return The log level.
67 static enum level
level();
71 * Import log functions to a script.
74 static void import(script
& script
);
78 * Construct a log with a certain priority and prefix string.
79 * \param level The log level.
80 * \param prefix The string printed before each log message.
82 log(enum level level
, const char* prefix
) :
84 prefix_(prefix
) /* only pass literal strings */ {}
88 void operator () (const A
& a
)
90 *this << a
<< std::endl
;
93 template <class A
, class B
>
94 void operator () (const A
& a
, const B
& b
)
96 *this << a
<< " " << b
<< std::endl
;
99 template <class A
, class B
, class C
>
100 void operator () (const A
& a
, const B
& b
, const C
& c
)
102 *this << a
<< " " << b
<< " " << c
<< std::endl
;
105 template <class A
, class B
, class C
, class D
>
106 void operator () (const A
& a
, const B
& b
, const C
& c
, const D
& d
)
108 *this << a
<< " " << b
<< " " << c
<< " " << d
<< std::endl
;
111 template <class A
, class B
, class C
, class D
, class E
>
112 void operator () (const A
& a
,
128 template <class T
> friend std::ostream
& operator << (log
&, const T
&);
130 static enum level gLevel
;
137 extern std::ostream
& log
;
138 extern std::ostream
& null_log
;
140 extern class log log_error
;
141 extern class log log_warning
;
142 extern class log log_info
;
146 inline std::ostream
& operator << (class log
& log
, const T
& item
)
148 if (log::gLevel
< log
.level_
) return null_log
;
149 return moof::log
<< log
.prefix_
<< item
;
155 #endif // _MOOF_LOG_HH_
This page took 0.04228 seconds and 5 git commands to generate.