Photon 1.0.0
Loading...
Searching...
No Matches
async_logger-inl.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#ifndef SPDLOG_HEADER_ONLY
8#endif
9
10#include <spdlog/sinks/sink.h>
12
13#include <memory>
14#include <string>
15
17 std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
18 : async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
19{
20}
21
23 std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
24 : async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
25{
26}
27
28// send the log message to the thread pool
30{
31 if (auto pool_ptr = thread_pool_.lock())
32 {
33 pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
34 }
35 else
36 {
37 throw_spdlog_ex("async log: thread pool doesn't exist anymore");
38 }
39}
40
41// send flush request to the thread pool
43{
44 if (auto pool_ptr = thread_pool_.lock())
45 {
46 pool_ptr->post_flush(shared_from_this(), overflow_policy_);
47 }
48 else
49 {
50 throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
51 }
52}
53
54//
55// backend functions - called from the thread pool to do the actual job
56//
58{
59 for (auto& sink : sinks_)
60 {
61 if (sink->should_log(msg.level))
62 {
64 {
65 sink->log(msg);
66 }
68 }
69 }
70
71 if (should_flush_(msg))
72 {
73 backend_flush_();
74 }
75}
76
78{
79 for (auto& sink : sinks_)
80 {
82 {
83 sink->flush();
84 }
86 }
87}
88
89SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
90{
91 auto cloned = std::make_shared<spdlog::async_logger>(*this);
92 cloned->name_ = std::move(new_name);
93 return cloned;
94}
Definition async_logger.h:36
std::shared_ptr< logger > clone(std::string new_name) override
Definition async_logger-inl.h:89
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
void flush_() override
Definition async_logger-inl.h:42
void backend_flush_()
Definition async_logger-inl.h:77
void sink_it_(const details::log_msg &msg) override
Definition async_logger-inl.h:29
void backend_sink_it_(const details::log_msg &incoming_log_msg)
Definition async_logger-inl.h:57
#define SPDLOG_TRY
Definition common.h:107
#define SPDLOG_INLINE
Definition common.h:47
#define SPDLOG_LOGGER_CATCH(location)
Definition logger.h:31
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
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
Definition common-inl.h:75
Definition uuid.h:926
Definition log_msg.h:14
level::level_enum level
Definition log_msg.h:23
source_loc source
Definition log_msg.h:31
Definition common.h:312