summaryrefslogtreecommitdiffstats
path: root/lib/base/journaldlogger.hpp
blob: 373dd1a6038c29f8c583318a28605c9eb7c3b122 (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
/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */

#ifndef JOURNALDLOGGER_H
#define JOURNALDLOGGER_H

#include "base/i2-base.hpp"
#if !defined(_WIN32) && defined(HAVE_SYSTEMD)
#include "base/journaldlogger-ti.hpp"
#include <sys/uio.h>

namespace icinga
{

/**
 * A logger that logs to systemd journald.
 *
 * @ingroup base
 */
class JournaldLogger final : public ObjectImpl<JournaldLogger>
{
public:
	DECLARE_OBJECT(JournaldLogger);
	DECLARE_OBJECTNAME(JournaldLogger);

	static void StaticInitialize();
	static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);

	void OnConfigLoaded() override;
	void ValidateFacility(const Lazy<String>& lvalue, const ValidationUtils& utils) override;

protected:
	void SystemdJournalSend(const std::vector<String>& varJournalFields) const;
	static struct iovec IovecFromString(const String& s);

	std::vector<String> m_ConfiguredJournalFields;

	void ProcessLogEntry(const LogEntry& entry) override;
	void Flush() override;
};

}
#endif /* !_WIN32 && HAVE_SYSTEMD */

#endif /* JOURNALDLOGGER_H */