Commit 032035e7 authored by gabime's avatar gabime

format

parent 66b5772b
...@@ -18,22 +18,26 @@ ...@@ -18,22 +18,26 @@
// Create a file logger which creates new files with a specified time step and fixed file size: // Create a file logger which creates new files with a specified time step and fixed file size:
// //
// std::shared_ptr<logger> step_logger_mt(const std::string &logger_name, const filename_t &filename, unsigned seconds = 60, const // std::shared_ptr<logger> step_logger_mt(const std::string &logger_name, const filename_t &filename, unsigned seconds = 60, const
// filename_t &tmp_ext = ".tmp", unsigned max_file_size = std::numeric_limits<unsigned>::max(), bool delete_empty_files = true, const filename_t &file_header = ""); std::shared_ptr<logger> // filename_t &tmp_ext = ".tmp", unsigned max_file_size = std::numeric_limits<unsigned>::max(), bool delete_empty_files = true, const
// step_logger_st(const std::string &logger_name, const filename_t &filename, unsigned seconds = 60, const filename_t &tmp_ext = ".tmp", // filename_t &file_header = ""); std::shared_ptr<logger> step_logger_st(const std::string &logger_name, const filename_t &filename,
// unsigned max_file_size = std::numeric_limits<unsigned>::max()); // unsigned seconds = 60, const filename_t &tmp_ext = ".tmp", unsigned max_file_size = std::numeric_limits<unsigned>::max());
// Example for spdlog_impl.h // Example for spdlog_impl.h
// Create a file logger that creates new files with a specified increment // Create a file logger that creates new files with a specified increment
// inline std::shared_ptr<spdlog::logger> spdlog::step_logger_mt( // inline std::shared_ptr<spdlog::logger> spdlog::step_logger_mt(
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size, bool delete_empty_files, const filename_t &file_header) // const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size,
// bool delete_empty_files, const filename_t &file_header)
// { // {
// return create<spdlog::sinks::step_file_sink_mt>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files, file_header); // return create<spdlog::sinks::step_file_sink_mt>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files,
// file_header);
// } // }
// inline std::shared_ptr<spdlog::logger> spdlog::step_logger_st( // inline std::shared_ptr<spdlog::logger> spdlog::step_logger_st(
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size, bool delete_empty_files, const filename_t &file_header) // const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size,
// bool delete_empty_files, const filename_t &file_header)
// { // {
// return create<spdlog::sinks::step_file_sink_st>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files, file_header); // return create<spdlog::sinks::step_file_sink_st>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files,
// file_header);
// } // }
namespace spdlog { namespace spdlog {
...@@ -64,7 +68,8 @@ template<class Mutex, class FileNameCalc = default_step_file_name_calculator> ...@@ -64,7 +68,8 @@ template<class Mutex, class FileNameCalc = default_step_file_name_calculator>
class step_file_sink SPDLOG_FINAL : public base_sink<Mutex> class step_file_sink SPDLOG_FINAL : public base_sink<Mutex>
{ {
public: public:
step_file_sink(filename_t base_filename, unsigned step_seconds, filename_t tmp_ext, unsigned max_size, bool delete_empty_files, filename_t file_header) step_file_sink(filename_t base_filename, unsigned step_seconds, filename_t tmp_ext, unsigned max_size, bool delete_empty_files,
filename_t file_header)
: _base_filename(std::move(base_filename)) : _base_filename(std::move(base_filename))
, _tmp_ext(std::move(tmp_ext)) , _tmp_ext(std::move(tmp_ext))
, _step_seconds(step_seconds) , _step_seconds(step_seconds)
...@@ -102,7 +107,8 @@ public: ...@@ -102,7 +107,8 @@ public:
if (!_current_size) if (!_current_size)
{ {
_current_size += _file_header.formatted.size(); _current_size += _file_header.formatted.size();
if (_current_size) _file_helper.write(_file_header); if (_current_size)
_file_helper.write(_file_header);
} }
} }
...@@ -142,7 +148,8 @@ protected: ...@@ -142,7 +148,8 @@ protected:
if (change_occured) if (change_occured)
{ {
_current_size = _file_header.formatted.size(); _current_size = _file_header.formatted.size();
if (_current_size) _file_helper.write(_file_header); if (_current_size)
_file_helper.write(_file_header);
} }
} }
...@@ -182,7 +189,8 @@ private: ...@@ -182,7 +189,8 @@ private:
if (details::file_helper::file_exists(_current_filename) && details::os::rename(_current_filename, target) != 0) if (details::file_helper::file_exists(_current_filename) && details::os::rename(_current_filename, target) != 0)
{ {
throw spdlog_ex("step_file_sink: failed renaming " + filename_to_str(_current_filename) + " to " + filename_to_str(target), errno); throw spdlog_ex(
"step_file_sink: failed renaming " + filename_to_str(_current_filename) + " to " + filename_to_str(target), errno);
} }
} }
......
...@@ -29,13 +29,11 @@ ...@@ -29,13 +29,11 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
namespace spdlog { namespace spdlog {
namespace details { namespace details {
class async_log_helper class async_log_helper
{ {
// Async msg to move to/from the queue // Async msg to move to/from the queue
// Movable only. should never be copied // Movable only. should never be copied
enum class async_msg_type enum class async_msg_type
...@@ -84,7 +82,7 @@ namespace spdlog { ...@@ -84,7 +82,7 @@ namespace spdlog {
} }
// copy into log_msg // copy into log_msg
void fill_log_msg(log_msg &msg, std::string* logger_name) void fill_log_msg(log_msg &msg, std::string *logger_name)
{ {
msg.logger_name = logger_name; msg.logger_name = logger_name;
msg.level = level; msg.level = level;
...@@ -96,18 +94,14 @@ namespace spdlog { ...@@ -96,18 +94,14 @@ namespace spdlog {
} }
}; };
public: public:
using item_type = async_msg; using item_type = async_msg;
using q_type = details::mpmc_bounded_queue<item_type>; using q_type = details::mpmc_bounded_queue<item_type>;
using clock = std::chrono::steady_clock; using clock = std::chrono::steady_clock;
async_log_helper(std::string logger_name, async_log_helper(std::string logger_name, formatter_ptr formatter, std::vector<sink_ptr> sinks, size_t queue_size,
formatter_ptr formatter, const log_err_handler err_handler, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
std::vector<sink_ptr> sinks,
size_t queue_size,
const log_err_handler err_handler,
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
std::function<void()> worker_warmup_cb = nullptr, std::function<void()> worker_warmup_cb = nullptr,
const std::chrono::milliseconds &flush_interval_ms = std::chrono::milliseconds::zero(), const std::chrono::milliseconds &flush_interval_ms = std::chrono::milliseconds::zero(),
std::function<void()> worker_teardown_cb = nullptr); std::function<void()> worker_teardown_cb = nullptr);
...@@ -126,7 +120,7 @@ namespace spdlog { ...@@ -126,7 +120,7 @@ namespace spdlog {
void set_error_handler(spdlog::log_err_handler err_handler); void set_error_handler(spdlog::log_err_handler err_handler);
private: private:
std::string _logger_name; std::string _logger_name;
formatter_ptr _formatter; formatter_ptr _formatter;
std::vector<std::shared_ptr<sinks::sink>> _sinks; std::vector<std::shared_ptr<sinks::sink>> _sinks;
...@@ -170,22 +164,16 @@ namespace spdlog { ...@@ -170,22 +164,16 @@ namespace spdlog {
void handle_flush_interval(); void handle_flush_interval();
void flush_sinks(); void flush_sinks();
}; };
} // namespace details } // namespace details
} // namespace spdlog } // namespace spdlog
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation // async_sink class implementation
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline spdlog::details::async_log_helper::async_log_helper(std::string logger_name, inline spdlog::details::async_log_helper::async_log_helper(std::string logger_name, formatter_ptr formatter, std::vector<sink_ptr> sinks,
formatter_ptr formatter, size_t queue_size, log_err_handler err_handler, const async_overflow_policy overflow_policy, std::function<void()> worker_warmup_cb,
std::vector<sink_ptr> sinks, const std::chrono::milliseconds &flush_interval_ms, std::function<void()> worker_teardown_cb)
size_t queue_size,
log_err_handler err_handler,
const async_overflow_policy overflow_policy,
std::function<void()> worker_warmup_cb,
const std::chrono::milliseconds &flush_interval_ms,
std::function<void()> worker_teardown_cb)
: _logger_name(std::move(logger_name)) : _logger_name(std::move(logger_name))
, _formatter(std::move(formatter)) , _formatter(std::move(formatter))
, _sinks(std::move(sinks)) , _sinks(std::move(sinks))
......
...@@ -21,8 +21,8 @@ inline spdlog::async_logger::async_logger(const std::string &logger_name, const ...@@ -21,8 +21,8 @@ inline spdlog::async_logger::async_logger(const std::string &logger_name, const
const async_overflow_policy overflow_policy, const std::function<void()> &worker_warmup_cb, const async_overflow_policy overflow_policy, const std::function<void()> &worker_warmup_cb,
const std::chrono::milliseconds &flush_interval_ms, const std::function<void()> &worker_teardown_cb) const std::chrono::milliseconds &flush_interval_ms, const std::function<void()> &worker_teardown_cb)
: logger(logger_name, begin, end) : logger(logger_name, begin, end)
, _async_log_helper(new details::async_log_helper( , _async_log_helper(new details::async_log_helper(logger_name, _formatter, _sinks, queue_size, _err_handler, overflow_policy,
logger_name, _formatter, _sinks, queue_size, _err_handler, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb)) worker_warmup_cb, flush_interval_ms, worker_teardown_cb))
{ {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment