diff --git a/Cargo.toml b/Cargo.toml index c19b111..6f19eb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,4 @@ [package] - name = "syslog" version = "7.0.0" authors = [ "contact@geoffroycouprie.com" ] @@ -8,9 +7,14 @@ license = "MIT" repository = "https://github.com/Geal/rust-syslog" documentation = "https://docs.rs/syslog" keywords = ["syslog", "logs", "logging"] +edition = "2024" [dependencies] hostname = "0.4" time = { version = "0.3.5", features = ["local-offset", "formatting"] } -log = { version = "0.4.8", features = [ "std" ] } +log = { version = "0.4.8", features = [ "std" ], optional = true } libc = "0.2.112" + +[features] +default = [ "log" ] +log = [ "dep:log" ] diff --git a/src/errors.rs b/src/errors.rs index 47aa0e0..f888709 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -20,9 +20,9 @@ impl std::error::Error for Error { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match *self { - Error::Initialization(ref err) => write!(f, "Initialization error: {}", err), - Error::Write(ref err) => write!(f, "Write error: {}", err), - Error::Io(ref err) => write!(f, "Io error: {}", err), + Error::Initialization(ref err) => write!(f, "Initialization error: {err}"), + Error::Write(ref err) => write!(f, "Write error: {err}"), + Error::Io(ref err) => write!(f, "Io error: {err}"), } } } diff --git a/src/format.rs b/src/format.rs index 3126426..6b594ac 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,13 +1,9 @@ use std::collections::BTreeMap; use std::fmt::Display; use std::io::Write; -use time; -use errors::*; -use facility::Facility; -use get_hostname; -use get_process_info; -use Priority; +use crate::errors::*; +use crate::{Facility, Priority, get_hostname, get_process_info}; #[allow(non_camel_case_types)] #[derive(Copy, Clone)] diff --git a/src/lib.rs b/src/lib.rs index 945aba9..7a50452 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,9 +51,6 @@ //! //! info!("hello world"); //! ``` -extern crate log; -extern crate time; - use std::env; use std::fmt::{self, Arguments}; use std::io::{self, BufWriter, Write}; @@ -64,6 +61,7 @@ use std::path::Path; use std::process; use std::sync::{Arc, Mutex}; +#[cfg(feature = "log")] use log::{Level, Log, Metadata, Record}; mod errors; @@ -340,6 +338,7 @@ impl BasicLogger { } } +#[cfg(feature = "log")] #[allow(unused_variables, unused_must_use)] impl Log for BasicLogger { fn enabled(&self, metadata: &Metadata) -> bool { @@ -367,6 +366,7 @@ impl Log for BasicLogger { } /// Unix socket Logger init function compatible with log crate +#[cfg(feature = "log")] #[cfg(unix)] pub fn init_unix(facility: Facility, log_level: log::LevelFilter) -> Result<()> { let (process, pid) = get_process_info()?; @@ -391,6 +391,7 @@ pub fn init_unix(_facility: Facility, _log_level: log::LevelFilter) -> Result<() } /// Unix socket Logger init function compatible with log crate and user provided socket path +#[cfg(feature = "log")] #[cfg(unix)] pub fn init_unix_custom>( facility: Facility, @@ -423,6 +424,7 @@ pub fn init_unix_custom>( } /// UDP Logger init function compatible with log crate +#[cfg(feature = "log")] pub fn init_udp( local: T, server: T, @@ -447,6 +449,7 @@ pub fn init_udp( } /// TCP Logger init function compatible with log crate +#[cfg(feature = "log")] pub fn init_tcp( server: T, hostname: String, @@ -482,6 +485,7 @@ pub fn init_tcp( /// this method doesn't return error even if there is no syslog. /// /// If `application_name` is `None` name is derived from executable name +#[cfg(feature = "log")] pub fn init( facility: Facility, log_level: log::LevelFilter,