remove 'info' and 'fatal' severities for logging to simplify framework - closes #1400

This commit is contained in:
Dane Springmeyer 2012-08-16 15:52:32 -07:00
parent 62d669907b
commit a986aedd05
9 changed files with 36 additions and 47 deletions

View file

@ -33,6 +33,7 @@ except:
HAS_DISTUTILS = False HAS_DISTUTILS = False
LIBDIR_SCHEMA_DEFAULT='lib' LIBDIR_SCHEMA_DEFAULT='lib'
severities = ['debug', 'warn', 'error', 'none']
py3 = None py3 = None
@ -343,7 +344,7 @@ opts.AddVariables(
# Variables for logging and statistics # Variables for logging and statistics
BoolVariable('ENABLE_LOG', 'Enable logging, which is enabled by default when building in *debug*', 'False'), BoolVariable('ENABLE_LOG', 'Enable logging, which is enabled by default when building in *debug*', 'False'),
BoolVariable('ENABLE_STATS', 'Enable global statistics during map processing', 'False'), BoolVariable('ENABLE_STATS', 'Enable global statistics during map processing', 'False'),
('DEFAULT_LOG_SEVERITY', 'The default severity of the logger (eg. "info", "debug", "warn", "error", "fatal", "none")', 'error'), ('DEFAULT_LOG_SEVERITY', 'The default severity of the logger (eg. ' + ', '.join(severities), 'error'),
# Other variables # Other variables
BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'), BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'),
@ -1470,7 +1471,6 @@ if not preconfigured:
ndebug_flags = '-DNDEBUG' ndebug_flags = '-DNDEBUG'
# Enable logging in debug mode (always) and release mode (when specified) # Enable logging in debug mode (always) and release mode (when specified)
severities = ['info', 'debug', 'warn', 'error', 'fatal', 'none']
if env['DEFAULT_LOG_SEVERITY']: if env['DEFAULT_LOG_SEVERITY']:
if env['DEFAULT_LOG_SEVERITY'] not in severities: if env['DEFAULT_LOG_SEVERITY'] not in severities:
severities_list = ', '.join(["'%s'" % s for s in severities]) severities_list = ', '.join(["'%s'" % s for s in severities])

View file

@ -39,22 +39,14 @@ void export_logger()
; ;
enum_<mapnik::logger::severity_type>("severity_type") enum_<mapnik::logger::severity_type>("severity_type")
.value("Info", logger::info)
.value("Debug", logger::debug) .value("Debug", logger::debug)
.value("Warn", logger::warn) .value("Warn", logger::warn)
.value("Error", logger::error) .value("Error", logger::error)
.value("Fatal", logger::fatal)
.value("None", logger::none) .value("None", logger::none)
; ;
class_<logger,bases<singleton<logger,CreateStatic> >, class_<logger,bases<singleton<logger,CreateStatic> >,
boost::noncopyable>("logger",no_init) boost::noncopyable>("logger",no_init)
.def_readonly("Info", logger::info)
.def_readonly("Debug", logger::debug)
.def_readonly("Warn", logger::warn)
.def_readonly("Error", logger::error)
.def_readonly("Fatal", logger::fatal)
.def_readonly("None", logger::none)
.def("get_severity", &logger::get_severity) .def("get_severity", &logger::get_severity)
.def("set_severity", &logger::set_severity) .def("set_severity", &logger::set_severity)
.def("get_object_severity", &logger::get_object_severity) .def("get_object_severity", &logger::get_object_severity)

View file

@ -55,12 +55,10 @@ namespace mapnik {
public: public:
enum severity_type enum severity_type
{ {
info, debug = 0,
debug, warn = 1,
warn, error = 2
error, none = 3
fatal,
none
}; };
typedef boost::unordered_map<std::string, severity_type> severity_map; typedef boost::unordered_map<std::string, severity_type> severity_map;
@ -180,7 +178,7 @@ namespace mapnik {
/* /*
Base log class, should not log anything when no MAPNIK_LOG is defined 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 This is used for debug/warn reporting that should not output
anything when not compiling for speed. anything when not compiling for speed.
*/ */
template<template <class Ch, class Tr, class A> class OutputPolicy, template<template <class Ch, class Tr, class A> class OutputPolicy,
@ -240,7 +238,7 @@ namespace mapnik {
/* /*
Base log class that always log, regardless of MAPNIK_LOG. Base log class that always log, regardless of MAPNIK_LOG.
This is used for error/fatal reporting that should always log something This is used for error reporting that should always log something
*/ */
template<template <class Ch, class Tr, class A> class OutputPolicy, template<template <class Ch, class Tr, class A> class OutputPolicy,
logger::severity_type Severity, logger::severity_type Severity,
@ -288,20 +286,18 @@ namespace mapnik {
}; };
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::debug> base_log_debug;
typedef base_log<clog_sink, logger::warn> base_log_warn; typedef base_log<clog_sink, logger::warn> base_log_warn;
typedef base_log_always<clog_sink, logger::error> base_log_error; typedef base_log_always<clog_sink, logger::error> base_log_error;
typedef base_log_always<clog_sink, logger::fatal> base_log_fatal;
} // namespace detail } // namespace detail
// real interfaces // real interfaces
class MAPNIK_DECL info : public detail::base_log_info { class MAPNIK_DECL warn : public detail::base_log_warn {
public: public:
info() : detail::base_log_info() {} warn() : detail::base_log_warn() {}
info(const char* object_name) : detail::base_log_info(object_name) {} warn(const char* object_name) : detail::base_log_warn(object_name) {}
}; };
class MAPNIK_DECL debug : public detail::base_log_debug { class MAPNIK_DECL debug : public detail::base_log_debug {
@ -310,31 +306,16 @@ namespace mapnik {
debug(const char* object_name) : detail::base_log_debug(object_name) {} debug(const char* object_name) : detail::base_log_debug(object_name) {}
}; };
class MAPNIK_DECL warn : public detail::base_log_warn {
public:
warn() : detail::base_log_warn() {}
warn(const char* object_name) : detail::base_log_warn(object_name) {}
};
class MAPNIK_DECL error : public detail::base_log_error { class MAPNIK_DECL error : public detail::base_log_error {
public: public:
error() : detail::base_log_error() {} error() : detail::base_log_error() {}
error(const char* object_name) : detail::base_log_error(object_name) {} error(const char* object_name) : detail::base_log_error(object_name) {}
}; };
class MAPNIK_DECL fatal : public detail::base_log_fatal {
public:
fatal() : detail::base_log_fatal() {}
fatal(const char* object_name) : detail::base_log_fatal(object_name) {}
};
// logging helpers // logging helpers
#define MAPNIK_LOG_INFO(s) mapnik::info(#s)
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s) #define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s) #define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s) #define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
#define MAPNIK_LOG_FATAL(s) mapnik::fatal(#s)
} }
#endif // MAPNIK_DEBUG_HPP #endif // MAPNIK_DEBUG_HPP

View file

@ -261,7 +261,7 @@ public:
{ {
if (our_strings_[i] == 0 ) if (our_strings_[i] == 0 )
{ {
MAPNIK_LOG_FATAL(enumeration) MAPNIK_LOG_ERROR(enumeration)
<< "### FATAL: Not enough strings for enum " << "### FATAL: Not enough strings for enum "
<< our_name_ << " defined in file '" << filename << our_name_ << " defined in file '" << filename
<< "' at line " << line_no; << "' at line " << line_no;
@ -270,7 +270,7 @@ public:
} }
if ( std::string("") != our_strings_[THE_MAX]) if ( std::string("") != our_strings_[THE_MAX])
{ {
MAPNIK_LOG_FATAL(enumeration) MAPNIK_LOG_ERROR(enumeration)
<< "### FATAL: The string array for enum " << our_name_ << "### FATAL: The string array for enum " << our_name_
<< " defined in file '" << filename << "' at line " << line_no << " defined in file '" << filename << "' at line " << line_no
<< " has too many items or is not terminated with an " << " has too many items or is not terminated with an "

View file

@ -146,7 +146,6 @@ public:
unsigned g = stop_color.green(); unsigned g = stop_color.green();
unsigned b = stop_color.blue(); unsigned b = stop_color.blue();
unsigned a = stop_color.alpha(); unsigned a = stop_color.alpha();
//MAPNIK_LOG_DEBUG(svg_renderer) << "svg_renderer: r=" << r << ",g=" << g << ",b=" << b << ",a=" << a;
m_gradient_lut.add_color(st.first, agg::rgba8_pre(r, g, b, int(a * opacity))); m_gradient_lut.add_color(st.first, agg::rgba8_pre(r, g, b, int(a * opacity)));
} }
m_gradient_lut.build_lut(); m_gradient_lut.build_lut();

View file

@ -152,7 +152,7 @@ featureset_ptr kismet_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
MAPNIK_LOG_INFO(kismet) << "kismet_datasource::features()"; MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features()";
// TODO: use box2d to filter bbox before adding to featureset_ptr // TODO: use box2d to filter bbox before adding to featureset_ptr
// mapnik::box2d<double> const& e = q.get_bbox(); // mapnik::box2d<double> const& e = q.get_bbox();
@ -170,7 +170,7 @@ featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
MAPNIK_LOG_INFO(kismet) << "kismet_datasource::features_at_point()"; MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features_at_point()";
return featureset_ptr(); return featureset_ptr();
} }

View file

@ -106,9 +106,10 @@ feature_ptr osm_featureset<filterT>::next()
static_cast<osm_way*>(cur_item)->nodes[count]->lat); static_cast<osm_way*>(cur_item)->nodes[count]->lat);
} }
feature->add_geometry(geom); feature->add_geometry(geom);
} else }
else
{ {
MAPNIK_LOG_FATAL(osm_featureset) << "Current item is neither node nor way.\n"; MAPNIK_LOG_ERROR(osm_featureset) << "Current item is neither node nor way.\n";
} }
std::set<std::string>::const_iterator itr = attribute_names_.begin(); std::set<std::string>::const_iterator itr = attribute_names_.begin();

View file

@ -58,9 +58,9 @@ bool logger::format_env_check_ = true;
logger::severity_type logger::severity_level_ = logger::severity_type logger::severity_level_ =
#if MAPNIK_DEFAULT_LOG_SEVERITY == 0 #if MAPNIK_DEFAULT_LOG_SEVERITY == 0
logger::info
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 1
logger::debug logger::debug
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 1
logger::info
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 2 #elif MAPNIK_DEFAULT_LOG_SEVERITY == 2
logger::warn logger::warn
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 3 #elif MAPNIK_DEFAULT_LOG_SEVERITY == 3

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
from nose.tools import *
import mapnik
def test_logger_init():
eq_(mapnik.severity_type.Debug,0)
eq_(mapnik.severity_type.Warn,1)
eq_(mapnik.severity_type.Error,2)
eq_(mapnik.severity_type.None,3)
default = mapnik.logger.get_severity()
mapnik.logger.set_severity(mapnik.severity_type.Debug)
eq_(mapnik.logger.get_severity(),mapnik.severity_type.Debug)
mapnik.logger.set_severity(default)
if __name__ == "__main__":
[eval(run)() for run in dir() if 'test_' in run]