]>
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
31 * Macro which tests an assertion and issues a log_error() and exits if the
33 * \param X test to perform
35 #define ASSERT(X) if (!(X)) moof::log_error \
36 << "false assertion at " << __FILE__ << ":" << __LINE__ << ", " \
48 * A class for handling a log priority. There are two ways to log
49 * messages: by treating a log object as a function whose parameters are
50 * printed with default spacing, or by treating a log object as an output
51 * stream. Either way, any object can be printed to the log as long as
52 * there is an override for the ostream insertion operator.
59 * A type for the level or priority of a log message.
63 none
= 0, ///< Disable all logging.
64 error
= 1, ///< Log only errors.
65 warning
= 2, ///< Log warnings and errors.
66 info
= 3, ///< Log everything.
71 * Set the lowest-priority log message that will be outputted to the
72 * log. Any logging with a lower priority will be ignored.
73 * \param level The log level.
75 static void level(level level
);
78 * Get the current lowest-priority log level. If unchanged, the
79 * default level is info.
80 * \return The log level.
82 static enum level
level();
86 * Import log functions to a script.
89 static void import(script
& script
);
93 * Construct a log with a certain priority and prefix string.
94 * \param level The log level.
95 * \param prefix The string printed before each log message.
97 log(enum level level
, const char* prefix
) :
99 prefix_(prefix
) /* only pass literal strings */ {}
103 void operator () (const A
& a
)
105 *this << a
<< std::endl
;
108 template <class A
, class B
>
109 void operator () (const A
& a
, const B
& b
)
111 *this << a
<< " " << b
<< std::endl
;
114 template <class A
, class B
, class C
>
115 void operator () (const A
& a
, const B
& b
, const C
& c
)
117 *this << a
<< " " << b
<< " " << c
<< std::endl
;
120 template <class A
, class B
, class C
, class D
>
121 void operator () (const A
& a
, const B
& b
, const C
& c
, const D
& d
)
123 *this << a
<< " " << b
<< " " << c
<< " " << d
<< std::endl
;
126 template <class A
, class B
, class C
, class D
, class E
>
127 void operator () (const A
& a
,
143 template <class T
> friend std::ostream
& operator << (log
&, const T
&);
145 static enum level gLevel
;
152 extern std::ostream
& log
;
153 extern std::ostream
& null_log
;
155 extern class log log_error
;
156 extern class log log_warning
;
157 extern class log log_info
;
161 inline std::ostream
& operator << (class log
& log
, const T
& item
)
163 if (log::gLevel
< log
.level_
) return null_log
;
164 return moof::log
<< log
.prefix_
<< item
;
170 #endif // _MOOF_LOG_HH_
This page took 0.038966 seconds and 4 git commands to generate.