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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2014-03-22 20:11:17 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Thread safe logger
|
2014-10-11 02:17:26 +08:00
|
|
|
// Has name, log level, vector of std::shared sink pointers and formatter
|
|
|
|
// Upon each log write the logger:
|
|
|
|
// 1. Checks if its log level is enough to log the message
|
|
|
|
// 2. Format the message using the formatter function
|
2014-10-15 05:46:14 +08:00
|
|
|
// 3. Pass the formatted message to its sinks to performa the actual logging
|
2014-10-11 02:17:26 +08:00
|
|
|
|
2014-03-22 20:11:17 +08:00
|
|
|
#include<vector>
|
|
|
|
#include<memory>
|
|
|
|
#include "sinks/base_sink.h"
|
2014-10-10 08:36:50 +08:00
|
|
|
#include "common.h"
|
2014-10-24 23:01:11 +08:00
|
|
|
|
2014-10-31 07:13:27 +08:00
|
|
|
namespace spdlog
|
2014-03-22 20:11:17 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
namespace details
|
|
|
|
{
|
|
|
|
class line_logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
class logger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-11-01 08:12:12 +08:00
|
|
|
logger(const std::string& logger_name, sink_ptr single_sink);
|
2014-10-24 06:59:39 +08:00
|
|
|
logger(const std::string& name, sinks_init_list);
|
2014-10-12 09:38:06 +08:00
|
|
|
template<class It>
|
2014-10-14 13:00:39 +08:00
|
|
|
logger(const std::string& name, const It& begin, const It& end);
|
2014-10-12 09:38:06 +08:00
|
|
|
|
2014-10-31 07:13:27 +08:00
|
|
|
void set_pattern(const std::string&);
|
2014-10-24 06:59:39 +08:00
|
|
|
void set_formatter(formatter_ptr);
|
|
|
|
formatter_ptr get_formatter() const;
|
|
|
|
|
|
|
|
|
2014-03-22 20:11:17 +08:00
|
|
|
logger(const logger&) = delete;
|
|
|
|
logger& operator=(const logger&) = delete;
|
|
|
|
|
2014-10-24 23:01:11 +08:00
|
|
|
void set_level(level::level_enum);
|
2014-10-11 02:32:10 +08:00
|
|
|
level::level_enum level() const;
|
2014-10-11 02:17:26 +08:00
|
|
|
|
|
|
|
const std::string& name() const;
|
2014-10-11 02:32:10 +08:00
|
|
|
bool should_log(level::level_enum) const;
|
2014-03-31 07:29:57 +08:00
|
|
|
|
2014-11-06 05:07:20 +08:00
|
|
|
//Stop logging
|
|
|
|
void stop();
|
2014-10-31 07:13:27 +08:00
|
|
|
|
2014-10-14 09:14:35 +08:00
|
|
|
template <typename... Args> details::line_logger log(level::level_enum lvl, const Args&... args);
|
2014-10-31 07:13:27 +08:00
|
|
|
template <typename... Args> details::line_logger log(const Args&... args);
|
2014-10-14 09:14:35 +08:00
|
|
|
template <typename... Args> details::line_logger trace(const Args&... args);
|
|
|
|
template <typename... Args> details::line_logger debug(const Args&... args);
|
2014-10-12 09:38:06 +08:00
|
|
|
template <typename... Args> details::line_logger info(const Args&... args);
|
2014-10-14 09:14:35 +08:00
|
|
|
template <typename... Args> details::line_logger warn(const Args&... args);
|
|
|
|
template <typename... Args> details::line_logger error(const Args&... args);
|
|
|
|
template <typename... Args> details::line_logger critical(const Args&... args);
|
2014-10-12 09:38:06 +08:00
|
|
|
|
2014-10-24 23:01:11 +08:00
|
|
|
|
2014-03-22 20:11:17 +08:00
|
|
|
private:
|
|
|
|
friend details::line_logger;
|
2014-10-11 02:32:10 +08:00
|
|
|
std::string _name;
|
2014-03-22 20:11:17 +08:00
|
|
|
formatter_ptr _formatter;
|
2014-10-14 13:00:39 +08:00
|
|
|
std::vector<sink_ptr> _sinks;
|
2014-10-11 02:17:26 +08:00
|
|
|
std::atomic_int _level;
|
2014-10-12 09:38:06 +08:00
|
|
|
void _variadic_log(details::line_logger& l);
|
2014-10-31 09:17:40 +08:00
|
|
|
template <typename Last>
|
|
|
|
inline void _variadic_log(spdlog::details::line_logger& l, const Last& last);
|
2014-10-12 09:38:06 +08:00
|
|
|
template <typename First, typename... Rest>
|
|
|
|
void _variadic_log(details::line_logger&l, const First& first, const Rest&... rest);
|
|
|
|
void _log_msg(details::log_msg& msg);
|
|
|
|
};
|
2014-10-24 23:01:11 +08:00
|
|
|
|
2014-10-25 05:32:56 +08:00
|
|
|
|
2014-10-31 07:13:27 +08:00
|
|
|
|
2014-03-22 20:11:17 +08:00
|
|
|
}
|
|
|
|
|
2014-10-25 05:44:02 +08:00
|
|
|
#include "./details/logger_impl.h"
|