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

Rework using the POSIX syslog API #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

argv-minus-one
Copy link

This PR reworks slog-syslog to use the POSIX syslog API. It is a breaking change. Supersedes PR #5.

As discussed in PR #5, this is based on the syslog backend that I wrote for sloggers and does not use the syslog crate. It is now very different from both slog-syslog 0.12 and PR #5. Differences from #5 include:

  • Uses the POSIX syslog API through the libc crate. (See “design and rationale” in src/lib.rs, starting at line 52, for details.) This means:
  • Only works on Unix-like platforms.
  • Only sends log messages to the local syslog daemon, not to a remote server.
  • Formats log messages into a reusable thread-local buffer, as in slog-syslog 0.12.
  • The Drain implementation is now called SyslogDrain instead of Streamer3164, since local syslog doesn't use the RFC3164 protocol.
  • If the serde feature is enabled, logging settings can be loaded from a configuration file.

Minimum supported Rust version is 1.27.2, or if the serde feature is enabled, 1.31.0. Doc-tests require 1.28.0. Works (except doc-tests) on 1.26.2 if you run the following commands first:

cargo generate-lockfile
cargo update --package lazy_static --precise 1.3.0
cargo update --package serde --precise 1.0.58
cargo update --package serde_derive --precise 1.0.58

As discussed in PR slog-rs#5, this is based on the [syslog backend that I wrote for sloggers][1] and does not use the `syslog` crate. It is now very different from both slog-syslog 0.12 and PR slog-rs#5. Differences from slog-rs#5 include:

* Uses the POSIX syslog API through the `libc` crate. (See “design and rationale” in src/lib.rs, starting at line 52, for details.) This means:
* Only works on Unix-like platforms.
* Only sends log messages to the local syslog daemon, not to a remote server.
* Formats log messages into a reusable thread-local buffer, as in slog-syslog 0.12.
* The `Drain` implementation is now called `SyslogDrain` instead of `Streamer3164`, since local syslog doesn't use the RFC3164 protocol.
* If the `serde` feature is enabled, logging settings can be loaded from a configuration file.

Minimum supported Rust version is 1.27.2, or if the `serde` feature is enabled, 1.31.0. Doc-tests require 1.28.0. Works (except doc-tests) on 1.26.2 if you run the following commands first:

```
cargo generate-lockfile
cargo update --package lazy_static --precise 1.3.0
cargo update --package serde --precise 1.0.58
cargo update --package serde_derive --precise 1.0.58
```

[1]: sile/sloggers#34
@eun-ice
Copy link

eun-ice commented Jul 13, 2020

Thank you so much for this, works on linux for me, but on macOS it just doesn't log anything. I did spend some time to figure out why but didn't find any issues at first glance.

But macOS syslog also doesn't work with original slog-syslog, which outputs this for every log statement:
thread '<unnamed>' panicked at 'slog::Fuse Drain: Error(Format, State { next_error: Some(Os { code: 55, kind: Other, message: "No buffer space available" }), backtrace: InternalBacktrace })', /Users/XXXX/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/macros.rs:16:9

@argv-minus-one
Copy link
Author

Strange. I just got ahold of a Mac and tested this, and it worked for me. One of the doc-tests emits an actual log message, and that message did indeed appear in the Mac Console app. It was pretty hard to spot among all the log messages that macOS itself generates, but it was there.

If you're sure it's not working for you, could you try running logger test and see if the message “test” appears in the system log? The logger command is built into macOS, but uses the same API as my code.

@eun-ice
Copy link

eun-ice commented Jul 15, 2020

I think what I didn't see is that only error!() and warn!() logs are printed, but not info nor debug!

cargo run --example syslog-unix
prints
default 16:11:23.200313+0200 syslog-unix Error [build-id="8dfljdf" who="slog-syslog test"]

I will check on how to configure this after my vacation. So far everything is fine for me.

@eun-ice
Copy link

eun-ice commented Jul 28, 2020

On macOS all info/debug syslog messages are dropped by default, they can be enabled using a configuration file in /etc/asl.conf .

I found out after I added support for setlogmask, in case you want to use it: argv-minus-one#1

@eun-ice
Copy link

eun-ice commented Jul 29, 2020

I made a proper pull request that solves everything for me argv-minus-one#2

Aron Wieck and others added 2 commits August 3, 2020 20:04
…n a per-message basis.

Thanks to @eun-ice for the idea and initial implementation.
@reyk
Copy link

reyk commented Apr 2, 2021

What happened to this work?

@argv-minus-one
Copy link
Author

@reyk There doesn't seem to be much interest from the maintainers.

@reyk
Copy link

reyk commented Apr 3, 2021

Your approach to use POSIX would actually make it more portable 👍

You can argue about support for sending to remote syslog servers without going through syslog, but for local syslog it is much better to rely on libc because the underlying API might be different. For example, this crate does not work on systems that use the sendsyslog(2) system call instead of the classic syslog UNIX socket. sendsyslog is an improvement because it provides a reliable kernel-backed queue and because it works inside of a sandbox/chroot (https://man.openbsd.org/sendsyslog).

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

Successfully merging this pull request may close these issues.

3 participants