Skip to content

Commit

Permalink
Merge pull request #121 from daboross/fmt-and-clippy
Browse files Browse the repository at this point in the history
Fix clippy lints & format
  • Loading branch information
daboross authored Mar 23, 2023
2 parents f8a0744 + 32a4d90 commit eb78920
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 77 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,15 @@ jobs:
toolchain: 1.59.0
override: true
- run: cargo build --features syslog-6
fmt_and_clippy:
name: Optional Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cargo fmt --check
- run: cargo clippy --all-features --all-targets -- -D warnings
2 changes: 1 addition & 1 deletion examples/pretty-colored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn set_up_logging() {
// configure colors for the name of the level.
// since almost all of them are the same as the color for the whole line, we
// just clone `colors_line` and overwrite our changes
let colors_level = colors_line.clone().info(Color::Green);
let colors_level = colors_line.info(Color::Green);
// here we set up our fern Dispatch
fern::Dispatch::new()
.format(move |out, message, record| {
Expand Down
6 changes: 0 additions & 6 deletions rustfmt.toml

This file was deleted.

26 changes: 9 additions & 17 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use crate::{log_impl, Filter, FormatCallback, Formatter};
use crate::log_impl::DateBasedState;

#[cfg(all(not(windows), feature = "syslog-4"))]
use crate::{Syslog4Rfc3164Logger, Syslog4Rfc5424Logger};
use crate::{Syslog4Rfc3164Logger, Syslog4Rfc5424Logger, Syslog4TransformFn};

#[cfg(all(not(windows), feature = "syslog-6"))]
use crate::{Syslog6Rfc3164Logger, Syslog6Rfc5424Logger};
use crate::{Syslog6Rfc3164Logger, Syslog6Rfc5424Logger, Syslog6TransformFn};

/// The base dispatch logger.
///
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Dispatch {
.levels
.iter()
.enumerate()
.find(|&(_, &(ref name, _))| name == &module)
.find(|(_, (name, _))| *name == module)
{
self.levels.remove(index);
}
Expand Down Expand Up @@ -576,11 +576,11 @@ impl Dispatch {
filters.shrink_to_fit();

let dispatch = log_impl::Dispatch {
output: output,
default_level: default_level,
output,
default_level,
levels: levels.into(),
format: format,
filters: filters,
format,
filters,
};

(real_min, dispatch)
Expand Down Expand Up @@ -696,23 +696,15 @@ enum OutputInner {
#[cfg(all(not(windows), feature = "syslog-4"))]
Syslog4Rfc5424 {
logger: Syslog4Rfc5424Logger,
transform: Box<
dyn Fn(&log::Record) -> (i32, HashMap<String, HashMap<String, String>>, String)
+ Sync
+ Send,
>,
transform: Box<Syslog4TransformFn>,
},
#[cfg(all(not(windows), feature = "syslog-6"))]
Syslog6Rfc3164(Syslog6Rfc3164Logger),
/// Sends all messages through the transform then passes to the syslog.
#[cfg(all(not(windows), feature = "syslog-6"))]
Syslog6Rfc5424 {
logger: Syslog6Rfc5424Logger,
transform: Box<
dyn Fn(&log::Record) -> (u32, HashMap<String, HashMap<String, String>>, String)
+ Sync
+ Send,
>,
transform: Box<Syslog6TransformFn>,
},
/// Panics with messages text for all messages.
Panic,
Expand Down
7 changes: 2 additions & 5 deletions src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ impl Default for ColoredLevelConfig {

impl ColoredLogLevel for Level {
fn colored(&self, color: Color) -> WithFgColor<Level> {
WithFgColor {
text: *self,
color: color,
}
WithFgColor { text: *self, color }
}
}

Expand Down Expand Up @@ -314,7 +311,7 @@ mod test {
"{}",
WithFgColor {
text: "test",
color: color,
color,
}
)
);
Expand Down
2 changes: 0 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{error, fmt, io};

use log;

/// Convenience error combining possible errors which could occur while
/// initializing logging.
///
Expand Down
21 changes: 14 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ use std::{
path::Path,
};

#[cfg(all(not(windows), feature = "syslog-4"))]
#[cfg(all(not(windows), any(feature = "syslog-4", feature = "syslog-6")))]
use std::collections::HashMap;

pub use crate::{
Expand Down Expand Up @@ -316,6 +316,14 @@ type Syslog6Rfc3164Logger = syslog6::Logger<syslog6::LoggerBackend, syslog6::For
#[cfg(all(not(windows), feature = "syslog-6"))]
type Syslog6Rfc5424Logger = syslog6::Logger<syslog6::LoggerBackend, syslog6::Formatter5424>;

#[cfg(all(not(windows), feature = "syslog-4"))]
type Syslog4TransformFn =
dyn Fn(&log::Record) -> (i32, HashMap<String, HashMap<String, String>>, String) + Send + Sync;

#[cfg(all(not(windows), feature = "syslog-6"))]
type Syslog6TransformFn =
dyn Fn(&log::Record) -> (u32, HashMap<String, HashMap<String, String>>, String) + Send + Sync;

/// Convenience method for opening a log file with common options.
///
/// Equivalent to:
Expand Down Expand Up @@ -367,9 +375,7 @@ pub fn log_reopen(path: &Path, signal: Option<libc::c_int>) -> io::Result<reopen
let r = reopen03::Reopen::new(Box::new(move || log_file(&p)))?;

if let Some(s) = signal {
if let Err(e) = r.handle().register_signal(s) {
return Err(e);
}
r.handle().register_signal(s)?;
}
Ok(r)
}
Expand All @@ -394,9 +400,10 @@ pub fn log_reopen(path: &Path, signal: Option<libc::c_int>) -> io::Result<reopen
/// This function requires the `reopen-1` feature to be enabled.
#[cfg(all(not(windows), feature = "reopen-1"))]
#[inline]
pub fn log_reopen1<S: IntoIterator<Item = libc::c_int>>(path: &Path, signals: S)
-> io::Result<reopen1::Reopen<File>>
{
pub fn log_reopen1<S: IntoIterator<Item = libc::c_int>>(
path: &Path,
signals: S,
) -> io::Result<reopen1::Reopen<File>> {
let p = path.to_owned();
let r = reopen1::Reopen::new(Box::new(move || log_file(&p)))?;

Expand Down
31 changes: 11 additions & 20 deletions src/log_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ use log::{self, Log};
use crate::{Filter, Formatter};

#[cfg(all(not(windows), feature = "syslog-4"))]
use crate::{Syslog4Rfc3164Logger, Syslog4Rfc5424Logger};
use crate::{Syslog4Rfc3164Logger, Syslog4Rfc5424Logger, Syslog4TransformFn};
#[cfg(all(not(windows), feature = "syslog-6"))]
use crate::{Syslog6Rfc3164Logger, Syslog6Rfc5424Logger};
#[cfg(all(not(windows), feature = "reopen-03"))]
use reopen03;
#[cfg(all(not(windows), feature = "reopen-1"))]
use reopen1;
use crate::{Syslog6Rfc3164Logger, Syslog6Rfc5424Logger, Syslog6TransformFn};

pub enum LevelConfiguration {
JustDefault,
Expand Down Expand Up @@ -140,11 +136,7 @@ pub struct Syslog4Rfc3164 {
#[cfg(all(not(windows), feature = "syslog-4"))]
pub struct Syslog4Rfc5424 {
pub inner: Mutex<Syslog4Rfc5424Logger>,
pub transform: Box<
dyn Fn(&log::Record) -> (i32, HashMap<String, HashMap<String, String>>, String)
+ Sync
+ Send,
>,
pub transform: Box<Syslog4TransformFn>,
}

#[cfg(all(not(windows), feature = "syslog-6"))]
Expand All @@ -155,11 +147,7 @@ pub struct Syslog6Rfc3164 {
#[cfg(all(not(windows), feature = "syslog-6"))]
pub struct Syslog6Rfc5424 {
pub inner: Mutex<Syslog6Rfc5424Logger>,
pub transform: Box<
dyn Fn(&log::Record) -> (u32, HashMap<String, HashMap<String, String>>, String)
+ Sync
+ Send,
>,
pub transform: Box<Syslog6TransformFn>,
}

pub struct Panic;
Expand Down Expand Up @@ -256,7 +244,7 @@ impl DateBasedConfig {
}

pub fn open_current_log_file(&self, suffix: &str) -> io::Result<fs::File> {
Self::open_log_file(&self.compute_file_path(&suffix))
Self::open_log_file(&self.compute_file_path(suffix))
}
}

Expand Down Expand Up @@ -317,8 +305,8 @@ impl LevelConfiguration {
LevelConfiguration::JustDefault => None,
LevelConfiguration::Minimal(ref levels) => levels
.iter()
.find(|&&(ref test_module, _)| test_module == module)
.map(|&(_, level)| level),
.find(|(test_module, _)| test_module == module)
.map(|(_, level)| *level),
LevelConfiguration::Many(ref levels) => levels.get(module).cloned(),
}
}
Expand Down Expand Up @@ -644,7 +632,10 @@ impl Log for Sender {
fn flush(&self) {}
}

#[cfg(all(not(windows), any(feature = "syslog-3", feature = "syslog-4", feature = "syslog-6")))]
#[cfg(all(
not(windows),
any(feature = "syslog-3", feature = "syslog-4", feature = "syslog-6")
))]
macro_rules! send_syslog {
($logger:expr, $level:expr, $message:expr) => {
use log::Level;
Expand Down
6 changes: 3 additions & 3 deletions tests/file_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_basic_logging_file_logging() {

{
let result = {
let mut log_read = fs::File::open(&temp_log_dir.path().join("test.log")).unwrap();
let mut log_read = fs::File::open(temp_log_dir.path().join("test.log")).unwrap();
let mut buf = String::new();
log_read.read_to_string(&mut buf).unwrap();
buf
Expand Down Expand Up @@ -80,7 +80,7 @@ fn test_custom_line_separators() {
// default log level is 'trace' if not specified (logs all messages)
// output to the log file with the "\r\n" line separator.
.chain(fern::Output::file(
fern::log_file(&log_file).expect("Failed to open log file"),
fern::log_file(log_file).expect("Failed to open log file"),
"\r\n",
))
.into_log();
Expand All @@ -95,7 +95,7 @@ fn test_custom_line_separators() {
{
let result = {
let mut log_read =
fs::File::open(&temp_log_dir.path().join("test_custom_line_sep.log")).unwrap();
fs::File::open(temp_log_dir.path().join("test_custom_line_sep.log")).unwrap();
let mut buf = String::new();
log_read.read_to_string(&mut buf).unwrap();
buf
Expand Down
20 changes: 7 additions & 13 deletions tests/global_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ impl LogVerify {
let formatted_message = format!("{}", record.args());
match &*formatted_message {
"[INFO] Test information message" => {
assert_eq!(self.info, false, "expected only one info message");
assert!(!self.info, "expected only one info message");
self.info = true;
}
"[WARN] Test warning message" => {
assert_eq!(self.warn, false, "expected only one warn message");
assert!(!self.warn, "expected only one warn message");
self.warn = true;
}
"[ERROR] Test error message" => {
assert_eq!(self.error, false, "expected only one error message");
assert!(!self.error, "expected only one error message");
self.error = true;
}
other => panic!("unexpected message: '{}'", other),
Expand Down Expand Up @@ -85,16 +85,10 @@ fn test_global_logger() {
log::logger().flush();

let verify_acquired = verify.0.lock().unwrap();
assert_eq!(
verify_acquired.info, true,
"expected info message to be received"
);
assert_eq!(
verify_acquired.warn, true,
"expected warn message to be received"
);
assert_eq!(
verify_acquired.error, true,
assert!(verify_acquired.info, "expected info message to be received");
assert!(verify_acquired.warn, "expected warn message to be received");
assert!(
verify_acquired.error,
"expected error message to be received"
);
}
2 changes: 1 addition & 1 deletion tests/meta_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn file_deadlock() {

{
let contents = {
let mut log_read = fs::File::open(&temp_log_dir.path().join("test.log")).unwrap();
let mut log_read = fs::File::open(temp_log_dir.path().join("test.log")).unwrap();
let mut buf = String::new();
log_read.read_to_string(&mut buf).unwrap();
buf
Expand Down
4 changes: 2 additions & 2 deletions tests/reopen_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_basic_logging_reopen_logging() {

{
let result = {
let mut log_read = fs::File::open(&temp_log_dir.path().join("test.log")).unwrap();
let mut log_read = fs::File::open(temp_log_dir.path().join("test.log")).unwrap();
let mut buf = String::new();
log_read.read_to_string(&mut buf).unwrap();
buf
Expand Down Expand Up @@ -96,7 +96,7 @@ fn test_custom_line_separators() {
{
let result = {
let mut log_read =
fs::File::open(&temp_log_dir.path().join("test_custom_line_sep.log")).unwrap();
fs::File::open(temp_log_dir.path().join("test_custom_line_sep.log")).unwrap();
let mut buf = String::new();
log_read.read_to_string(&mut buf).unwrap();
buf
Expand Down

0 comments on commit eb78920

Please sign in to comment.