Skip to content

Commit

Permalink
Merge pull request #52 from ssahani/namespace
Browse files Browse the repository at this point in the history
Allow to send log from a directory
  • Loading branch information
ssahani authored May 1, 2024
2 parents 2568121 + 3422c73 commit d685486
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions src/netlog/netlog-gperf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 19 additions & 5 deletions src/netlog/netlog-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions src/netlog/netlog-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Manager {
char *state_file;
char *last_cursor, *current_cursor;
char *structured_data;
char *dir;

SysLogTransmissionProtocol protocol;
SysLogTransmissionLogFormat log_format;
Expand Down

0 comments on commit d685486

Please sign in to comment.