- added the ability to set the default global severity from scons configure
- initial check in of setting global severity from getenv (todo)
This commit is contained in:
parent
46d45e8496
commit
81c9dd7b6b
3 changed files with 65 additions and 6 deletions
16
SConstruct
16
SConstruct
|
@ -348,6 +348,7 @@ opts.AddVariables(
|
||||||
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'),
|
||||||
('LOG_FORMAT_STRING', 'The format string used before log output string, piped through strftime (max length of 255 characters)', 'Mapnik LOG> %Y-%m-%d %H:%M:%S:'),
|
('LOG_FORMAT_STRING', 'The format string used before log output string, piped through strftime (max length of 255 characters)', 'Mapnik LOG> %Y-%m-%d %H:%M:%S:'),
|
||||||
|
('DEFAULT_LOG_SEVERITY', 'The default severity of the logger (eg. "info", "debug", "warn", "error", "fatal", "none")', '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'),
|
||||||
|
@ -1417,7 +1418,20 @@ 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)
|
||||||
log_enabled = ' -DMAPNIK_LOG -DMAPNIK_LOG_FORMAT="%s"' % env['LOG_FORMAT_STRING']
|
if env['DEFAULT_LOG_SEVERITY']:
|
||||||
|
severities = ['info', 'debug', 'warn', 'error', 'fatal', 'none']
|
||||||
|
if env['DEFAULT_LOG_SEVERITY'] not in severities:
|
||||||
|
color_print(1,"Cannot set default logger severity to '%s', available options are 'info', 'debug', 'warn', 'error', 'fatal', 'none'." % env['DEFAULT_LOG_SEVERITY'])
|
||||||
|
Exit(1)
|
||||||
|
else:
|
||||||
|
log_severity = severities.index(env['DEFAULT_LOG_SEVERITY'])
|
||||||
|
else:
|
||||||
|
if env['DEBUG']:
|
||||||
|
log_severity = 1 # debug
|
||||||
|
else:
|
||||||
|
log_severity = 3 # error
|
||||||
|
|
||||||
|
log_enabled = ' -DMAPNIK_LOG -DMAPNIK_LOG_FORMAT="%s" -DMAPNIK_DEFAULT_LOG_SEVERITY=%d' % (env['LOG_FORMAT_STRING'], log_severity)
|
||||||
|
|
||||||
if env['DEBUG']:
|
if env['DEBUG']:
|
||||||
debug_flags += log_enabled
|
debug_flags += log_enabled
|
||||||
|
|
|
@ -125,6 +125,7 @@ namespace mapnik {
|
||||||
format_ = format;
|
format_ = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// interpolate the format string for output
|
||||||
static std::string str();
|
static std::string str();
|
||||||
|
|
||||||
// output
|
// output
|
||||||
|
@ -134,7 +135,11 @@ namespace mapnik {
|
||||||
private:
|
private:
|
||||||
static severity_type severity_level_;
|
static severity_type severity_level_;
|
||||||
static severity_map object_severity_level_;
|
static severity_map object_severity_level_;
|
||||||
|
static bool severity_env_check_;
|
||||||
|
|
||||||
static std::string format_;
|
static std::string format_;
|
||||||
|
static bool format_env_check_;
|
||||||
|
|
||||||
static std::ofstream file_output_;
|
static std::ofstream file_output_;
|
||||||
static std::string file_name_;
|
static std::string file_name_;
|
||||||
static std::streambuf* saved_buf_;
|
static std::streambuf* saved_buf_;
|
||||||
|
|
|
@ -30,22 +30,48 @@
|
||||||
#define MAPNIK_LOG_FORMAT "Mapnik LOG> %Y-%m-%d %H:%M:%S:"
|
#define MAPNIK_LOG_FORMAT "Mapnik LOG> %Y-%m-%d %H:%M:%S:"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAPNIK_DEFAULT_LOG_SEVERITY
|
||||||
|
#ifdef MAPNIK_DEBUG
|
||||||
|
#define MAPNIK_DEFAULT_LOG_SEVERITY 1
|
||||||
|
#else
|
||||||
|
#define MAPNIK_DEFAULT_LOG_SEVERITY 3
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
// mutexes
|
||||||
|
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
boost::mutex logger::severity_mutex_;
|
boost::mutex logger::severity_mutex_;
|
||||||
boost::mutex logger::format_mutex_;
|
boost::mutex logger::format_mutex_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// first time checks
|
||||||
|
|
||||||
|
bool logger::severity_env_check_ = true;
|
||||||
|
bool logger::format_env_check_ = true;
|
||||||
|
|
||||||
|
|
||||||
// severity
|
// severity
|
||||||
|
|
||||||
logger::severity_type logger::severity_level_ =
|
logger::severity_type logger::severity_level_ =
|
||||||
#ifdef MAPNIK_DEBUG
|
#if MAPNIK_DEFAULT_LOG_SEVERITY == 0
|
||||||
logger::debug
|
logger::info
|
||||||
#else
|
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 1
|
||||||
logger::error
|
logger::debug
|
||||||
#endif
|
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 2
|
||||||
|
logger::warn
|
||||||
|
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 3
|
||||||
|
logger::error
|
||||||
|
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 4
|
||||||
|
logger::fatal
|
||||||
|
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 5
|
||||||
|
logger::none
|
||||||
|
#else
|
||||||
|
#error "Wrong default log severity level specified!"
|
||||||
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
logger::severity_map logger::object_severity_level_ = logger::severity_map();
|
logger::severity_map logger::object_severity_level_ = logger::severity_map();
|
||||||
|
@ -61,6 +87,20 @@ std::string logger::format_ = __xstr__(MAPNIK_LOG_FORMAT);
|
||||||
|
|
||||||
std::string logger::str()
|
std::string logger::str()
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
// update the format from getenv if this is the first time
|
||||||
|
if (logger::format_env_check_)
|
||||||
|
{
|
||||||
|
logger::format_env_check_ = false;
|
||||||
|
|
||||||
|
const char* log_format = getenv("MAPNIK_LOG_FORMAT");
|
||||||
|
if (log_format != NULL)
|
||||||
|
{
|
||||||
|
logger::format_ = log_format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
const time_t tm = time(0);
|
const time_t tm = time(0);
|
||||||
strftime(buf, sizeof(buf), logger::format_.c_str(), localtime(&tm));
|
strftime(buf, sizeof(buf), logger::format_.c_str(), localtime(&tm));
|
||||||
|
|
Loading…
Reference in a new issue