This repository was archived by the owner on Mar 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.hpp
More file actions
129 lines (106 loc) · 3.78 KB
/
logger.hpp
File metadata and controls
129 lines (106 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*------------------------------------------------------------------------------
*
* Header and interface for the logging framework.
*
* Author: matt.amos@mapquest.com
*
* Copyright 2010-1 Mapquest, Inc. All Rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*-----------------------------------------------------------------------------*/
#ifndef LOGGING_LOGGER_HPP
#define LOGGING_LOGGER_HPP
#include <boost/property_tree/ptree.hpp>
#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <mapnik/utils.hpp>
#include <string>
namespace logging {
namespace log_level {
enum type
{
finer = 0,
debug = 1,
info = 2,
warning = 3,
error = 4
};
}
/* base of all logger types. loggers are created by a factory function
* and accessed entirely through this interface.
*/
class logger
: private boost::noncopyable
{
public:
// output a log message at the given log level
virtual void log(log_level::type, const std::string &) = 0;
virtual ~logger();
};
class log
: public mapnik::singleton<log, mapnik::CreateStatic>,
private boost::noncopyable
{
public:
friend class mapnik::CreateStatic<log>;
// utility methods to do logging
static void finer(const boost::format &);
static void debug(const boost::format &);
static void info(const boost::format &);
static void warning(const boost::format &);
static void error(const boost::format &);
static void finer(const std::string &);
static void debug(const std::string &);
static void info(const std::string &);
static void warning(const std::string &);
static void error(const std::string &);
// to configure the log
static void configure(const boost::property_tree::ptree &);
static std::string get_utc_offset_string();
log();
private:
boost::scoped_ptr<logger> m_logger;
static boost::posix_time::time_duration get_utc_offset();
};
// factory function to create loggers. if you implement one of these, register
// it statically with the register_logger() function below.
typedef logger *(*logger_creator)(const boost::property_tree::ptree &);
// call this function from the logger implementation to register the
// creation function with the singleton factory.
bool register_logger(const std::string &type, logger_creator func);
// create a logger instance from the given configuration. note that
// the caller owns the returned pointer.
logger *create_logger(const boost::property_tree::ptree &);
} // namespace logging
#ifndef LOGGING_MACROS
#define LOGGING_MACROS
// for convenience, some macros to make logging prettier.
#ifdef RENDERMQ_DEBUG
#define LOG_FINER(x) ::logging::log::finer(x)
#define LOG_DEBUG(x) ::logging::log::debug(x)
#else /* RENDERMQ_DEBUG */
// don't even generate code for debug logging if debug mode
// isn't turned on...
#define LOG_FINER(x)
#define LOG_DEBUG(x)
#endif /* RENDERMQ_DEBUG */
#define LOG_INFO(x) ::logging::log::info(x)
#define LOG_WARNING(x) ::logging::log::warning(x)
#define LOG_ERROR(x) ::logging::log::error(x)
#endif /* LOGGING_MACROS */
#endif /* LOGGING_LOGGER_HPP */