Permalink
Browse files

- always log errors and fatals, regardless of MAPNIK_LOG definition

  • Loading branch information...
1 parent e947d7e commit d717c715fc312c62859ce42e40e92dc2336e166e @kunitoki kunitoki committed Apr 12, 2012
Showing with 69 additions and 2 deletions.
  1. +69 −2 include/mapnik/debug.hpp
View
@@ -44,6 +44,10 @@
namespace mapnik {
+ /*
+ Global logger class that holds the configuration of severity, format
+ and file/console redirection.
+ */
class MAPNIK_DECL logger :
public singleton<logger,CreateStatic>,
private boost::noncopyable
@@ -153,6 +157,9 @@ namespace mapnik {
namespace detail {
+ /*
+ Default sink, it regulates access to clog
+ */
template<class Ch, class Tr, class A>
class clog_sink
{
@@ -170,6 +177,12 @@ namespace mapnik {
};
+ /*
+ Base log class, should not log anything when no MAPNIK_LOG is defined
+
+ This is used for info/debug/warn reporting that should not output
+ anything when not compiling for speed.
+ */
template<template <class Ch, class Tr, class A> class OutputPolicy,
logger::severity_type Severity,
class Ch = char,
@@ -223,14 +236,67 @@ namespace mapnik {
#endif
};
+
+ /*
+ Base log class that always log, regardless of MAPNIK_LOG.
+
+ This is used for error/fatal reporting that should always log something
+ */
+ template<template <class Ch, class Tr, class A> class OutputPolicy,
+ logger::severity_type Severity,
+ class Ch = char,
+ class Tr = std::char_traits<Ch>,
+ class A = std::allocator<Ch> >
+ class base_log_always : public boost::noncopyable
+ {
+ public:
+ typedef OutputPolicy<Ch, Tr, A> output_policy;
+
+ base_log_always() {}
+
+ base_log_always(const char* object_name)
+ {
+ if (object_name != NULL)
+ {
+ object_name_ = object_name;
+ }
+ }
+
+ ~base_log_always()
+ {
+ if (check_severity())
+ {
+ output_policy()(Severity, streambuf_);
+ }
+ }
+
+ template<class T>
+ base_log_always &operator<<(const T &x)
+ {
+ streambuf_ << x;
+ return *this;
+ }
+
+ private:
+ inline bool check_severity()
+ {
+ return Severity >= logger::get_object_severity(object_name_);
+ }
+
+ typename output_policy::stream_buffer streambuf_;
+ std::string object_name_;
+ };
+
+
typedef base_log<clog_sink, logger::info> base_log_info;
typedef base_log<clog_sink, logger::debug> base_log_debug;
typedef base_log<clog_sink, logger::warn> base_log_warn;
- typedef base_log<clog_sink, logger::error> base_log_error;
- typedef base_log<clog_sink, logger::fatal> base_log_fatal;
+ typedef base_log_always<clog_sink, logger::error> base_log_error;
+ typedef base_log_always<clog_sink, logger::fatal> base_log_fatal;
} // namespace detail
+
// real interfaces
class MAPNIK_DECL info : public detail::base_log_info {
public:
@@ -262,6 +328,7 @@ namespace mapnik {
fatal(const char* object_name) : detail::base_log_fatal(object_name) {}
};
+
// logging helpers
#define MAPNIK_LOG_INFO(s) mapnik::info(#s)
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)

0 comments on commit d717c71

Please sign in to comment.