spdlog/include/spdlog/spdlog.h

144 lines
5.2 KiB
C
Raw Normal View History

2014-11-01 09:20:54 +08:00
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2014 Gabi Melman. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
// spdlog main header file.
//see example.cpp for usage example
2014-10-31 07:13:27 +08:00
#pragma once
#include "logger.h"
namespace spdlog
{
// Return an existing logger or nullptr if a logger with such name doesn't exist.
// Examples:
//
// spdlog::get("mylog")->info("Hello");
// auto logger = spdlog::get("mylog");
// logger.info("This is another message" , x, y, z);
// logger.info() << "This is another message" << x << y << z;
std::shared_ptr<logger> get(const std::string& name);
2014-12-02 08:16:56 +08:00
//
// Drop the reference to this logger.
//
void drop(const std::string &name);
2014-10-31 07:13:27 +08:00
2014-11-24 07:29:09 +08:00
//
// Set global formatting
2014-11-24 07:29:09 +08:00
// e.g. spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
//
void set_pattern(const std::string& format_string);
2014-11-24 07:29:09 +08:00
void set_formatter(formatter_ptr f);
2014-11-24 07:29:09 +08:00
//
// Set global logging level
//
void set_level(level::level_enum log_level);
2014-11-24 07:29:09 +08:00
//
// Async mode - off by default.
//
// Turn on async mode and set the queue size for each async_logger
2014-12-07 10:18:07 +08:00
void set_async_mode(size_t queue_size);
2014-11-24 07:29:09 +08:00
// Turn off async mode
void set_sync_mode();
//
// Create multi/single threaded rotating file logger
2014-11-24 07:29:09 +08:00
//
2014-11-25 06:27:28 +08:00
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 auto_flush = false);
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 auto_flush = false);
2014-11-24 07:29:09 +08:00
//
// Create file logger which creates new file at midnight):
2014-11-24 07:29:09 +08:00
//
2014-11-25 06:27:28 +08:00
std::shared_ptr<logger> daily_logger_mt(const std::string& logger_name, const std::string& filename, bool auto_flush = false);
std::shared_ptr<logger> daily_logger_st(const std::string& logger_name, const std::string& filename, bool auto_flush = false);
2014-11-24 07:29:09 +08:00
//
// Create stdout/stderr loggers
2014-11-24 07:29:09 +08:00
//
std::shared_ptr<logger> stdout_logger_mt(const std::string& logger_name);
std::shared_ptr<logger> stdout_logger_st(const std::string& logger_name);
std::shared_ptr<logger> stderr_logger_mt(const std::string& logger_name);
std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
2014-10-31 07:13:27 +08:00
2014-11-24 07:29:09 +08:00
//
// Create a syslog logger
2014-11-24 07:29:09 +08:00
//
#ifdef __linux__
2014-12-20 00:01:49 +08:00
std::shared_ptr<logger> syslog_logger(const std::string& logger_name, const std::string& ident = "", int syslog_option = 0);
#endif
//
// Create a logger with multiple sinks
//
std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks);
2014-10-31 07:13:27 +08:00
template<class It>
std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
// Create a logger with templated sink type
// Example: spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
template <typename Sink, typename... Args>
std::shared_ptr<spdlog::logger> create(const std::string& logger_name, const Args&...);
2014-10-31 07:13:27 +08:00
//
2014-12-18 16:07:21 +08:00
// Trace & debug macros to be switched on/off at compile time for zero cost debug statements.
// Note: using these mactors overrides the runtime log threshold of the logger.
//
// Example:
//
// Enable debug macro, must be defined before including spdlog.h
// #define SPDLOG_DEBUG_ON
// include "spdlog/spdlog.h"
// SPDLOG_DEBUG(my_logger, "Some debug message {} {}", 1, 3.2);
2014-10-31 07:13:27 +08:00
//
2014-12-18 16:07:21 +08:00
#ifdef SPDLOG_TRACE_ON
#define SPDLOG_TRACE(logger, ...) logger->force_log(spdlog::level::trace, __VA_ARGS__) << " (" << __FILE__ << " #" << __LINE__ <<")";
2014-10-31 07:13:27 +08:00
#else
2014-12-18 16:07:21 +08:00
#define SPDLOG_TRACE(logger, ...)
2014-10-31 07:13:27 +08:00
#endif
2014-12-18 16:07:21 +08:00
#ifdef SPDLOG_DEBUG_ON
#define SPDLOG_DEBUG(logger, ...) logger->force_log(spdlog::level::debug, __VA_ARGS__)
2014-12-18 16:07:21 +08:00
#else
#define SPDLOG_DEBUG(logger, ...)
#endif
2014-10-31 07:13:27 +08:00
}
2014-11-01 09:20:54 +08:00
#include "details/spdlog_impl.h"