]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
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 | ||
1e59de90 TL |
16 | class Entry; |
17 | class SubsystemMap; | |
18 | ||
20effc67 TL |
19 | #ifdef WITH_SYSTEMD |
20 | ||
21 | namespace detail { | |
22 | ||
23 | class EntryEncoder; | |
24 | class LogEntryEncoder; | |
25 | ||
26 | class JournaldClient { | |
27 | public: | |
28 | JournaldClient(); | |
29 | ~JournaldClient(); | |
30 | int send(); | |
31 | struct msghdr m_msghdr; | |
32 | private: | |
33 | int fd; | |
34 | ||
35 | enum class MemFileMode; | |
36 | MemFileMode mem_file_mode; | |
37 | ||
38 | void detect_mem_file_mode(); | |
39 | int open_mem_file(); | |
40 | }; | |
41 | } | |
42 | ||
20effc67 TL |
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 |