]>
Dogcows Code - chaz/yoink/blob - src/moof/log.hh
1e2a2163e119b2988b33312a091375ed2b04a6c6
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
34 * A class for handling a log priority. There are two ways to log
35 * messages: by treating a log object as a function whose parameters are
36 * printed with default spacing, or by treating a log object as an output
37 * stream. Either way, any object can be printed to the log as long as
38 * there is an override for the ostream insertion operator.
45 * A type for the level or priority of a log message.
49 none
= 0, ///< Disable all logging.
50 error
= 1, ///< Log only errors.
51 warning
= 2, ///< Log warnings and errors.
52 info
= 3, ///< Log everything.
53 debug
= 4, ///< Log absolutely everything.
58 * Set the lowest-priority log message that will be outputted to the
59 * log. Any logging with a lower priority will be ignored.
60 * \param level The log level.
62 static void level(level level
);
65 * Get the current lowest-priority log level. If unchanged, the
66 * default level is info.
67 * \return The log level.
69 static enum level
level();
73 * Import log functions to a script.
76 static void import(script
& script
);
80 * Construct a log with a certain priority and prefix string.
81 * \param level The log level.
82 * \param prefix The string printed before each log message.
84 log(enum level level
);
88 * Output this to end a line. This is equivalent to std::endl except
89 * this will also reset terminal format attributes.
97 void operator () (const A
& a
)
102 template <class A
, class B
>
103 void operator () (const A
& a
, const B
& b
)
105 *this << a
<< " " << b
<< endl
;
108 template <class A
, class B
, class C
>
109 void operator () (const A
& a
, const B
& b
, const C
& c
)
111 *this << a
<< " " << b
<< " " << c
<< endl
;
114 template <class A
, class B
, class C
, class D
>
115 void operator () (const A
& a
, const B
& b
, const C
& c
, const D
& d
)
117 *this << a
<< " " << b
<< " " << c
<< " " << d
<< endl
;
120 template <class A
, class B
, class C
, class D
, class E
>
121 void operator () (const A
& a
,
137 template <class T
> friend std::ostream
& operator << (log
&, const T
&);
138 friend std::ostream
& operator << (log
&, endl_
);
140 static enum level global_level_
;
147 extern std::ostream
& log
;
148 extern std::ostream
& null_log
;
150 extern class log log_error
;
151 extern class log log_warning
;
152 extern class log log_info
;
153 extern class log log_debug
;
157 inline std::ostream
& operator << (class log
& log
, const T
& item
)
159 if (log::global_level_
< log
.level_
) return null_log
;
160 return moof::log
<< log
.prefix_
<< item
;
163 std::ostream
& operator << (class log
& log
, log::endl_ endl
);
164 std::ostream
& operator << (std::ostream
& stream
, log::endl_ endl
);
169 #endif // _MOOF_LOG_HH_
This page took 0.049458 seconds and 4 git commands to generate.