summaryrefslogtreecommitdiffstats
path: root/src/common/Journald.h
blob: 377b1ff9eb6429bc8830531e086049c364412dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_COMMON_JOURNALD_H
#define CEPH_COMMON_JOURNALD_H

#include "acconfig.h"
#include <memory>
#include <sys/types.h>
#include <sys/socket.h>

struct LogEntry;

namespace ceph::logging {

class Entry;
class SubsystemMap;

#ifdef WITH_SYSTEMD

namespace detail {

class EntryEncoder;
class LogEntryEncoder;

class JournaldClient {
 public:
  JournaldClient();
  ~JournaldClient();
  int send();
  struct msghdr m_msghdr;
 private:
  int fd;

  enum class MemFileMode;
  MemFileMode mem_file_mode;

  void detect_mem_file_mode();
  int open_mem_file();
};
}

/**
 * Logger to send local logs to journald
 * 
 * local logs means @code dout(0) << ... @endcode and similars
 * 
 * @see JournaldClusterLogger
 */
class JournaldLogger {
 public:
  JournaldLogger(const SubsystemMap *s);
  ~JournaldLogger();

  /**
   * @returns 0 if log entry is successfully sent, -1 otherwise.
   */
  int log_entry(const Entry &e);

 private:
  detail::JournaldClient client;

  std::unique_ptr<detail::EntryEncoder> m_entry_encoder;

  const SubsystemMap * m_subs;
};

/**
 * Logger to send cluster log recieved by MON to journald
 * 
 * @see JournaldLogger
 */
class JournaldClusterLogger {
 public:
  JournaldClusterLogger();
  ~JournaldClusterLogger();

  /**
   * @returns 0 if log entry is successfully sent, -1 otherwise.
   */
  int log_log_entry(const LogEntry &le);

 private:
  detail::JournaldClient client;

  std::unique_ptr<detail::LogEntryEncoder> m_log_entry_encoder;
};

#else  // WITH_SYSTEMD

class JournaldLogger {
public:
  JournaldLogger(const SubsystemMap *) {}
  int log_entry(const Entry &) {
    return 0;
  }
};

class JournaldClusterLogger {
public:
  int log_log_entry(const LogEntry &le) {
    return 0;
  }
};

#endif // WITH_SYSTEMD

} // ceph::logging

#endif