Geal / rust-syslog

Send syslog messages from Rust
MIT License
109 stars 55 forks source link

Standard init for `log` crate #2

Closed tailhook closed 9 years ago

tailhook commented 9 years ago

It seems this crate have Log implemented but does no init() method. Is this intentional? Should I use log::set_logger with a lambda directly? (The log crate does not recommend this)

Geal commented 9 years ago

There are three different loggers: Unix socket, remote UDP and remote TCP, so I cannot have one init() methods, there are three such methods. I'll add the set_loggercall to those initialization methods.

tailhook commented 9 years ago

@Geal, sure three methods is ok. It's also probably nice to integrate with fern too (presumably under feature flag), because fern can write to multiple loggers at once.

Geal commented 9 years ago

Hi! Please tell me i this works ok for you.

tailhook commented 9 years ago
  1. It seems you need to set log_level:
  log::set_logger(|max_level| {
    max_level.set(LogLevel::Debug.to_log_level_filter());
    unix(facility)
  })

At least I have not found any other way of setting log level in rust. And both env_logger and fern does the same.

  1. For my own uses I need to customize application name 95% of the time
  2. I get the following in the log:
Aug 07 17:52:57 basin write[5579]: 2015-08-07T14:52:57Z localhost write[5579]: test error

I.e. duplicate date, host, application, pid. First ones are added by syslog daemon itself i.e. systemd in my case. In python app I get this:

Aug 07 18:17:01 basin myapp[9053]: error

What is exactly what expected. And what python sends to syslog is just "<11>myapp: error\0". I.e. my custom application name without pid, host, datetime.