diff --git a/README.md b/README.md index 4e3d312..f2205ac 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Creating user: sudo useradd -r -d / -s /usr/sbin/nologin -g systemd-journal systemd-journal-netlog ``` or via sysusers - + ``` /usr/lib/sysusers.d/systemd-netlogd.conf``` ```bash #Type Name ID GECOS Home directory Shell @@ -63,7 +63,11 @@ systemd-netlogd reads configuration files named `/etc/systemd/netlogd.conf` and LogFormat= Specifies whether to use RFC 5424 format or RFC 3339 format. Takes one of rfc5424 or rfc3339. Defaults to rfc5424. - Optional settings + + Directory= + Takes a directory path. Specifies whether to operate on the specified journal directory DIR instead of the default runtime and system journal paths. + + Optional settings StructuredData= Meta information about the syslog message, which can be used for Cloud Based diff --git a/doc/index.rst b/doc/index.rst index 4c3b22a..96fd02b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -39,6 +39,9 @@ This will create a user systemd-journal-netlog | LogFormat= Specifies whether to use RFC 5424 format or RFC 3339 format. Takes one of rfc5424 or rfc3339. Defaults to rfc5424. +| Directory= + Takes a directory path. Specifies whether to operate on the specified journal directory DIR instead of the default runtime and system journal paths. + | Optional settings | StructuredData= diff --git a/src/netlog/netlog-gperf.gperf b/src/netlog/netlog-gperf.gperf index e6b305c..ba296e1 100644 --- a/src/netlog/netlog-gperf.gperf +++ b/src/netlog/netlog-gperf.gperf @@ -18,6 +18,7 @@ struct ConfigPerfItem; Network.Address, config_parse_netlog_remote_address, 0, 0 Network.Protocol, config_parse_protocol, 0, offsetof(Manager, protocol) Network.LogFormat, config_parse_log_format, 0, offsetof(Manager, log_format) +Network.Directory, config_parse_string, 0, offsetof(Manager, dir) Network.StructuredData, config_parse_string, 0, offsetof(Manager, structured_data) Network.UseSysLogStructuredData, config_parse_bool, 0, offsetof(Manager, syslog_structured_data) Network.UseSysLogMsgId, config_parse_bool, 0, offsetof(Manager, syslog_msgid) diff --git a/src/netlog/netlog-manager.c b/src/netlog/netlog-manager.c index c640d45..9d37747 100644 --- a/src/netlog/netlog-manager.c +++ b/src/netlog/netlog-manager.c @@ -320,20 +320,34 @@ static int manager_signal_event_handler(sd_event_source *event, const struct sig return 0; } +static int open_journal(Manager *m) { + int r; + + assert(m); + + if (m->dir) + r = sd_journal_open_directory(&m->journal, m->dir, 0); + else + r = sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY); + + if (r < 0) + log_error_errno(r, "Failed to open %s: %m", m->dir ?: "journal"); + + return 0; +} + static int manager_journal_monitor_listen(Manager *m) { int r, events; assert(m); - r = sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY); - if (r < 0) { - log_error_errno(r, "Failed to open journal: %m"); + r = open_journal(m); + if (r < 0) return r; - } sd_journal_set_data_threshold(m->journal, 0); - m->journal_watch_fd = sd_journal_get_fd(m->journal); + m->journal_watch_fd = sd_journal_get_fd(m->journal); if (m->journal_watch_fd < 0) return log_error_errno(m->journal_watch_fd, "Failed to get journal fd: %m"); diff --git a/src/netlog/netlog-manager.h b/src/netlog/netlog-manager.h index d664838..b89845e 100644 --- a/src/netlog/netlog-manager.h +++ b/src/netlog/netlog-manager.h @@ -46,6 +46,7 @@ struct Manager { char *state_file; char *last_cursor, *current_cursor; char *structured_data; + char *dir; SysLogTransmissionProtocol protocol; SysLogTransmissionLogFormat log_format;