Photon 1.0.0
Loading...
Searching...
No Matches
async_logger.h
Go to the documentation of this file.
1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
5
6// Fast asynchronous logger.
7// Uses pre allocated queue.
8// Creates a single back thread to pop messages from the queue and log them.
9//
10// Upon each log write the logger:
11// 1. Checks if its log level is enough to log the message
12// 2. Push a new copy of the message to a queue (or block the caller until
13// space is available in the queue)
14// Upon destruction, logs all remaining messages in the queue before
15// destructing..
16
17#include <spdlog/logger.h>
18
19namespace spdlog
20{
21
22 // Async overflow policy - block by default.
24 {
25 block, // Block until message can be enqueued
26 overrun_oldest // Discard oldest message in the queue if full when trying to
27 // add new item.
28 };
29
30 namespace details
31 {
32 class thread_pool;
33 }
34
35 class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>, public logger
36 {
38
39 public:
40 template <typename It>
41 async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy = async_overflow_policy::block)
42 : logger(std::move(logger_name), begin, end), thread_pool_(std::move(tp)), overflow_policy_(overflow_policy)
43 {
44 }
45
46 async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy = async_overflow_policy::block);
47
48 async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy = async_overflow_policy::block);
49
50 std::shared_ptr<logger> clone(std::string new_name) override;
51
52 protected:
53 void sink_it_(const details::log_msg& msg) override;
54 void flush_() override;
55 void backend_sink_it_(const details::log_msg& incoming_log_msg);
56 void backend_flush_();
57
58 private:
59 std::weak_ptr<details::thread_pool> thread_pool_;
61 };
62} // namespace spdlog
63
64#ifdef SPDLOG_HEADER_ONLY
65#include "async_logger-inl.h"
66#endif
Definition async_logger.h:36
async_logger(std::string logger_name, It begin, It end, std::weak_ptr< details::thread_pool > tp, async_overflow_policy overflow_policy=async_overflow_policy::block)
Definition async_logger.h:41
std::weak_ptr< details::thread_pool > thread_pool_
Definition async_logger.h:59
async_overflow_policy overflow_policy_
Definition async_logger.h:60
Definition thread_pool.h:82
Definition logger.h:56
#define SPDLOG_API
Definition common.h:45
Definition async.h:26
std::shared_ptr< sinks::sink > sink_ptr
Definition common.h:136
async_overflow_policy
Definition async_logger.h:24
std::initializer_list< sink_ptr > sinks_init_list
Definition common.h:137
Definition uuid.h:926
Definition log_msg.h:14
annotation details
Definition tag_strings.h:125