-
Notifications
You must be signed in to change notification settings - Fork 18
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
syslog Logger's messages get dropped by daemon(3) #58
Comments
That behavior sounds strange. As for the question, is this issue specific to |
I can't reproduce it with TerminalLoggerBuilder. I haven't tried FileLoggerBuilder. |
I see. Thank you. |
I've been occupied for a while, but I believe I can investigate this issue this week. |
I was unable to build the code above on my macOS machine:
At the moment, I don't have a Linux machine, so it seems difficult to investigate the problem in detail. By the way, the comment in |
Another possibility is that the implicit |
This example should work on OSX, but you'll have to use a patched version of Nix. [patch.crates-io]
nix = { git = "https://github.com/asomers/nix.git", branch="apple-daemon"} |
Thank you. I'll try the patch this weekend. |
Hmm, I encountered the following error after enabling the patch: $ cargo check --manifest-path /Users/tohta/dev/rust/sloggers/Cargo.toml
Updating git repository `https://github.com/asomers/nix.git`
error: failed to load source for dependency `nix`
Caused by:
Unable to update https://github.com/asomers/nix.git?branch=apple-daemon
Caused by:
failed to find branch `apple-daemon`
Caused by:
cannot locate remote-tracking branch 'origin/apple-daemon'; class=Reference (4); code=NotFound (-3) |
Oops, I must've forgotten to push it. Sorry. Please try again. |
Thank you. I was able to build the patched version. Upon investigation, it turned out that this behavior is not unique to // This example code is based on the slog's official example:
// - https://docs.rs/slog/latest/slog/#logging-to-a-file
use slog::Drain;
use std::fs::OpenOptions;
fn main() {
let log_path = "/tmp/issue58.log";
let file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(log_path)
.unwrap();
let decorator = slog_term::PlainDecorator::new(file);
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
let logger = slog::Logger::root(drain, slog::o!());
slog::info!(logger, "hello");
// Without this line, the "hello" message will not be logged to the file (though there is some stochastic behavior involved)
std::thread::sleep(std::time::Duration::from_millis(500));
nix::unistd::daemon(false, false).unwrap();
// This message will disappear if the daemon() function above is called.
slog::info!(logger, "world");
std::thread::sleep(std::time::Duration::from_millis(500));
} It appears that |
Hey, great work! I'll take this issue up in the slog repo. Thanks for your help. |
daemon(3) is a handy helper to create a daemon process. It closes stdin, stdout, and stderr, forks the process, exits the parent, and leaves the child running. Unfortunately, using daemon(3) with sloggers's syslog module results in messages being lost.
Internally, daemon(3) calls exit(3) in the parent process. That would explain why the parent process doesn't actually send the messages. But the
Logger
object lives on in the child process. Why doesn't the child ever send the messages?Reproducer:
The text was updated successfully, but these errors were encountered: