-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A while back the syslog crate was updated to v7. This PR adds compatibility with this new version in fern. Also added `.vscode` to the `.gitignore` and fixed a comment where it mentioned `syslog-4` where it should have been `syslog-6` Signed-off-by: BlackDex <black.dex@gmail.com>
- Loading branch information
Showing
7 changed files
with
266 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ nb-configuration.xml | |
*.iws | ||
*.sublime-project | ||
*.sublime-workspace | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#[cfg(not(windows))] | ||
// This is necessary because `fern` depends on both version 3, 4 and 6 | ||
use syslog7 as syslog; | ||
|
||
#[cfg(not(windows))] | ||
use log::{debug, info, warn}; | ||
|
||
#[cfg(not(windows))] | ||
fn setup_logging() -> Result<(), Box<dyn std::error::Error>> { | ||
let syslog_fmt = syslog::Formatter3164 { | ||
facility: syslog::Facility::LOG_USER, | ||
hostname: None, | ||
process: "fern-syslog-example".into(), | ||
pid: 0, | ||
}; | ||
fern::Dispatch::new() | ||
// by default only accept warning messages so as not to spam | ||
.level(log::LevelFilter::Warn) | ||
// but accept Info if we explicitly mention it | ||
.level_for("explicit-syslog", log::LevelFilter::Info) | ||
.chain(syslog::unix(syslog_fmt)?) | ||
.apply()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(not(windows))] | ||
fn main() { | ||
setup_logging().expect("failed to initialize logging."); | ||
|
||
// None of this will be shown in the syslog: | ||
for i in 0..5 { | ||
info!("executing section: {}", i); | ||
|
||
debug!("section {} 1/4 complete.", i); | ||
|
||
debug!("section {} 1/2 complete.", i); | ||
|
||
debug!("section {} 3/4 complete.", i); | ||
|
||
info!("section {} completed!", i); | ||
} | ||
|
||
// these two *will* show. | ||
|
||
info!(target: "explicit-syslog", "hello to the syslog! this is rust."); | ||
|
||
warn!("AHHH something's on fire."); | ||
} | ||
|
||
#[cfg(windows)] | ||
fn main() { | ||
panic!("this example does not work on Windows."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.