Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature to allow zerolog to output SystemD compatible binary logs. #52

Closed
SAFAD opened this issue Apr 15, 2018 · 5 comments
Closed

Comments

@SAFAD
Copy link

SAFAD commented Apr 15, 2018

The current behavior of zerlog binary output is to support CBOR encoding, however, with systemD emerging and being used in almost every Linux Distribution (Debian, CentOS, RHEL, SLES which are Distributions dedicated for enterprise/server consumption mainly).

One could argue that it is beneficial to implement the journalD (logger service integrated with systemD) to allow persistent logging and even a concise way to log information across a server-stack.

The following links provide information about this feature request:

Two things to point out however, journalD binary files are highly corruptible and I personally do not favor them, however this is not about opinions, but providing the right tool for the general public.

The current STD logging in zerolog works perfectly fine when using journalctl -u goservice.service however, the logs are not persistent and lose all the data on restart/reboot of the system or service, thus the need for the "journaling" integration.

Thank you, and Best of Luck!

@toravir
Copy link
Contributor

toravir commented Apr 19, 2018

From what i read, journalD looks like a Key:Value logging mechanism - Key & Value are both strings. Sent to the systemD which will compress it and store it (log rotate it etc). There are methods to retrieve it / query it etc..

Any client of journalD will need to send a Priority + Message + (Key+Value) Pairs - over a unix socket to journalD or systemD.

Is my understand right ?? If so, this will be another kind of writer - like consoleWriter.. instead of formatting the log message for printing to console - this journaldWriter will convert logs to journalD format (Prio + Msg + KV Pairs) and send it to systemd ??

CBOR (binary) encoding does not add much value to it - since the logs are to be converted to strings to be sent to journalD.

@rs
Copy link
Owner

rs commented Apr 19, 2018

My understanding is that journald fields is a flat structure with no typing support. We might just want to create a writer that would set the priority field and set the message field with the JSON payload.

@toravir
Copy link
Contributor

toravir commented Apr 19, 2018

I have written a writer that will write to journald. I tested it by writing an example program. I could use some ideas on how to write a go-test to add tests. First cut diff: toravir@163f52c

@rs
Copy link
Owner

rs commented Apr 27, 2018

Fixed by #57

@rs rs closed this as completed Apr 27, 2018
@wvh
Copy link

wvh commented May 19, 2018

Note to the OP that the way you log to journald (redirecting stdout/stderr or using its socket) is not related to the logs being persistent. If you want journald logs to be persistent, you need to configure it so by setting the Storage option to persistent or creating the output directory if it's set to auto. Otherwise they will be in memory only (for most distributions) and will be lost on reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants