MINIFI-34 Establishing CMake build system to provide build functionality equivalent...
[nifi-minifi-cpp.git] / include / spdlog / spdlog.h
1 /*************************************************************************/
2 /* spdlog - an extremely fast and easy to use c++11 logging library. */
3 /* Copyright (c) 2014 Gabi Melman. */
4 /* */
5 /* Permission is hereby granted, free of charge, to any person obtaining */
6 /* a copy of this software and associated documentation files (the */
7 /* "Software"), to deal in the Software without restriction, including */
8 /* without limitation the rights to use, copy, modify, merge, publish, */
9 /* distribute, sublicense, and/or sell copies of the Software, and to */
10 /* permit persons to whom the Software is furnished to do so, subject to */
11 /* the following conditions: */
12 /* */
13 /* The above copyright notice and this permission notice shall be */
14 /* included in all copies or substantial portions of the Software. */
15 /* */
16 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
17 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
18 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
19 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
20 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
21 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
22 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 /*************************************************************************/
24
25
26 // spdlog main header file.
27 //see example.cpp for usage example
28
29 #pragma once
30
31 #include "tweakme.h"
32 #include "common.h"
33 #include "logger.h"
34
35 namespace spdlog
36 {
37 // Return an existing logger or nullptr if a logger with such name doesn't exist.
38 // Examples:
39 //
40 // spdlog::get("mylog")->info("Hello");
41 // auto logger = spdlog::get("mylog");
42 // logger.info("This is another message" , x, y, z);
43 // logger.info() << "This is another message" << x << y << z;
44 std::shared_ptr<logger> get(const std::string& name);
45
46 //
47 // Set global formatting
48 // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
49 //
50 void set_pattern(const std::string& format_string);
51 void set_formatter(formatter_ptr f);
52
53 //
54 // Set global logging level for
55 //
56 void set_level(level::level_enum log_level);
57
58 //
59 // Turn on async mode (off by default) and set the queue size for each async_logger.
60 // effective only for loggers created after this call.
61 // queue_size: size of queue (must be power of 2):
62 // Each logger will pre-allocate a dedicated queue with queue_size entries upon construction.
63 //
64 // async_overflow_policy (optional, block_retry by default):
65 // async_overflow_policy::block_retry - if queue is full, block until queue has room for the new log entry.
66 // async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows.
67 //
68 // worker_warmup_cb (optional):
69 // callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity)
70 //
71 void set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function<void()>& worker_warmup_cb = nullptr, const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero());
72
73 // Turn off async mode
74 void set_sync_mode();
75
76 //
77 // Create and register multi/single threaded rotating file logger
78 //
79 std::shared_ptr<logger> rotating_logger_mt(const std::string& logger_name, const std::string& filename, size_t max_file_size, size_t max_files, bool force_flush = false);
80 std::shared_ptr<logger> rotating_logger_st(const std::string& logger_name, const std::string& filename, size_t max_file_size, size_t max_files, bool force_flush = false);
81
82 //
83 // Create file logger which creates new file on the given time (default in midnight):
84 //
85 std::shared_ptr<logger> daily_logger_mt(const std::string& logger_name, const std::string& filename, int hour=0, int minute=0, bool force_flush = false);
86 std::shared_ptr<logger> daily_logger_st(const std::string& logger_name, const std::string& filename, int hour=0, int minute=0, bool force_flush = false);
87
88
89 //
90 // Create and register stdout/stderr loggers
91 //
92 std::shared_ptr<logger> stdout_logger_mt(const std::string& logger_name);
93 std::shared_ptr<logger> stdout_logger_st(const std::string& logger_name);
94 std::shared_ptr<logger> stderr_logger_mt(const std::string& logger_name);
95 std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
96
97
98 //
99 // Create and register a syslog logger
100 //
101 #ifdef __linux__
102 std::shared_ptr<logger> syslog_logger(const std::string& logger_name, const std::string& ident = "", int syslog_option = 0);
103 #endif
104
105
106 // Create and register a logger with multiple sinks
107 std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks);
108 template<class It>
109 std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
110
111
112 // Create and register a logger with templated sink type
113 // Example: spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
114 template <typename Sink, typename... Args>
115 std::shared_ptr<spdlog::logger> create(const std::string& logger_name, const Args&...);
116
117
118 // Register the given logger with the given name
119 void register_logger(std::shared_ptr<logger> logger);
120
121 // Drop the reference to the given logger
122 void drop(const std::string &name);
123
124 // Drop all references
125 void drop_all();
126
127
128 ///////////////////////////////////////////////////////////////////////////////
129 //
130 // Macros to be display source file & line
131 // Trace & Debug can be switched on/off at compile time for zero cost debug statements.
132 // Uncomment SPDLOG_DEBUG_ON/SPDLOG_TRACE_ON in teakme.h to enable.
133 //
134 // Example:
135 // spdlog::set_level(spdlog::level::debug);
136 // SPDLOG_DEBUG(my_logger, "Some debug message {} {}", 1, 3.2);
137 ///////////////////////////////////////////////////////////////////////////////
138
139 #ifdef SPDLOG_TRACE_ON
140 #define SPDLOG_TRACE(logger, ...) logger->trace(__VA_ARGS__) << " (" << __FILE__ << " #" << __LINE__ <<")";
141 #else
142 #define SPDLOG_TRACE(logger, ...)
143 #endif
144
145 #ifdef SPDLOG_DEBUG_ON
146 #define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__) << " (" << __FILE__ << " #" << __LINE__ <<")";
147 #else
148 #define SPDLOG_DEBUG(logger, ...)
149 #endif
150
151
152 }
153
154
155 #include "details/spdlog_impl.h"