Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]

name = "syslog"
version = "7.0.0"
authors = [ "contact@geoffroycouprie.com" ]
Expand All @@ -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" ]
6 changes: 3 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()?;
Expand All @@ -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<P: AsRef<Path>>(
facility: Facility,
Expand Down Expand Up @@ -423,6 +424,7 @@ pub fn init_unix_custom<P: AsRef<Path>>(
}

/// UDP Logger init function compatible with log crate
#[cfg(feature = "log")]
pub fn init_udp<T: ToSocketAddrs>(
local: T,
server: T,
Expand All @@ -447,6 +449,7 @@ pub fn init_udp<T: ToSocketAddrs>(
}

/// TCP Logger init function compatible with log crate
#[cfg(feature = "log")]
pub fn init_tcp<T: ToSocketAddrs>(
server: T,
hostname: String,
Expand Down Expand Up @@ -482,6 +485,7 @@ pub fn init_tcp<T: ToSocketAddrs>(
/// 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,
Expand Down