]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/Journald.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / common / Journald.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_COMMON_JOURNALD_H
5 #define CEPH_COMMON_JOURNALD_H
6
7 #include "acconfig.h"
8 #include <memory>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11
12 struct LogEntry;
13
14 namespace ceph::logging {
15
16 #ifdef WITH_SYSTEMD
17
18 namespace detail {
19
20 class EntryEncoder;
21 class LogEntryEncoder;
22
23 class JournaldClient {
24 public:
25 JournaldClient();
26 ~JournaldClient();
27 int send();
28 struct msghdr m_msghdr;
29 private:
30 int fd;
31
32 enum class MemFileMode;
33 MemFileMode mem_file_mode;
34
35 void detect_mem_file_mode();
36 int open_mem_file();
37 };
38 }
39
40 class Entry;
41 class SubsystemMap;
42
43 /**
44 * Logger to send local logs to journald
45 *
46 * local logs means @code dout(0) << ... @endcode and similars
47 *
48 * @see JournaldClusterLogger
49 */
50 class JournaldLogger {
51 public:
52 JournaldLogger(const SubsystemMap *s);
53 ~JournaldLogger();
54
55 /**
56 * @returns 0 if log entry is successfully sent, -1 otherwise.
57 */
58 int log_entry(const Entry &e);
59
60 private:
61 detail::JournaldClient client;
62
63 std::unique_ptr<detail::EntryEncoder> m_entry_encoder;
64
65 const SubsystemMap * m_subs;
66 };
67
68 /**
69 * Logger to send cluster log recieved by MON to journald
70 *
71 * @see JournaldLogger
72 */
73 class JournaldClusterLogger {
74 public:
75 JournaldClusterLogger();
76 ~JournaldClusterLogger();
77
78 /**
79 * @returns 0 if log entry is successfully sent, -1 otherwise.
80 */
81 int log_log_entry(const LogEntry &le);
82
83 private:
84 detail::JournaldClient client;
85
86 std::unique_ptr<detail::LogEntryEncoder> m_log_entry_encoder;
87 };
88
89 #else // WITH_SYSTEMD
90
91 class JournaldLogger {
92 public:
93 JournaldLogger(const SubsystemMap *) {}
94 int log_entry(const Entry &) {
95 return 0;
96 }
97 };
98
99 class JournaldClusterLogger {
100 public:
101 int log_log_entry(const LogEntry &le) {
102 return 0;
103 }
104 };
105
106 #endif // WITH_SYSTEMD
107
108 } // ceph::logging
109
110 #endif