From 8833da5509650a64063acc9f8692dd908e0aa275 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 21 Sep 2024 16:11:59 +0800 Subject: [PATCH 1/2] chore: tidy build and readme Signed-off-by: tison --- .github/workflows/rust.yml | 42 +++++++++----------------------------- .travis.yml | 41 ------------------------------------- Cargo.toml | 10 ++++----- README.md | 13 +++--------- rust-toolchain.toml | 3 +++ 5 files changed, 21 insertions(+), 88 deletions(-) delete mode 100644 .travis.yml create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 12b025e..1149b0b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,21 +11,10 @@ env: jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Cache - uses: actions/cache@v2 - with: - path: | - ~/.cargo - target/ - key: ${{ runner.os }}-${{ hashFiles('Cargo.toml') }} - restore-keys: | - ${{ runner.os }}-${{ hashFiles('Cargo.toml') }} - ${{ runner.os }}- + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 - name: Build run: cargo build --verbose - name: Run tests @@ -35,28 +24,17 @@ jobs: name: Coverage runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - name: Install rust - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@v2 with: - toolchain: stable - profile: minimal - override: true - - name: Cache - uses: Swatinem/rust-cache@v1 - - name: Install cargo-tarpaulin - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-tarpaulin + tool: cargo-tarpaulin - name: Run cargo tarpaulin - uses: actions-rs/cargo@v1 - with: - command: tarpaulin - args: --output-dir coverage --out xml --workspace --tests --example log --example rfc5424 --example write + run: | + cargo tarpaulin --output-dir coverage --out xml --workspace --tests \ + --example log --example rfc5424 --example write - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 with: token: ${{ secrets.CODECOV_TOKEN }} - slug: Geal/rust-syslog \ No newline at end of file + slug: Geal/rust-syslog diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 597e6e3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: rust - -addons: - apt: - packages: - - libcurl4-openssl-dev - - libelf-dev - - libdw-dev - -rust: - - nightly - - beta - - stable - -before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - -script: - - travis-cargo build - - travis-cargo test - - travis-cargo bench - - travis-cargo --only stable doc - -after_success: - - travis-cargo coveralls --no-sudo - -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/9c035a194ac4fd4cc061 - on_success: change - on_failure: always - on_start: false - - -env: - global: - # override the default `--features unstable` used for the nightly branch (optional) - - TRAVIS_CARGO_NIGHTLY_FEATURE=nightly - -sudo: false diff --git a/Cargo.toml b/Cargo.toml index c19b111..ab44ba3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] - name = "syslog" version = "7.0.0" +edition = "2021" authors = [ "contact@geoffroycouprie.com" ] description = "Syslog message formatter and writer, supporting unix sockets, UDP and TCP exporters" license = "MIT" @@ -10,7 +10,7 @@ documentation = "https://docs.rs/syslog" keywords = ["syslog", "logs", "logging"] [dependencies] -hostname = "0.4" -time = { version = "0.3.5", features = ["local-offset", "formatting"] } -log = { version = "0.4.8", features = [ "std" ] } -libc = "0.2.112" +hostname = { version = "0.4" } +libc = { version = "0.2.112" } +log = { version = "0.4.8", features = [ "std" ] } +time = { version = "0.3.5", features = ["local-offset", "formatting"] } diff --git a/README.md b/README.md index 2b8e8a7..9558bd1 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,16 @@ syslog is available on [crates.io](https://crates.io/crates/syslog) and can be i ```toml [dependencies] -syslog = "^6.0" +syslog = "^7.0" ``` -## documentation +## Documentation Reference documentation is available [here](https://docs.rs/syslog). ## Example ```rust -extern crate syslog; - use syslog::{Facility, Formatter3164}; fn main() { @@ -46,12 +44,8 @@ fn main() { The struct `syslog::Logger` implements `Log` from the `log` crate, so it can be used as backend for other logging systems: ```rust -extern crate syslog; -#[macro_use] -extern crate log; - use syslog::{Facility, Formatter3164, BasicLogger}; -use log::{SetLoggerError, LevelFilter}; +use log::{SetLoggerError, LevelFilter, info}; fn main() { let formatter = Formatter3164 { @@ -67,7 +61,6 @@ fn main() { info!("hello world"); } - ``` There are 3 functions to create loggers: diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..751ab8c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +components = ["cargo", "rustfmt", "clippy", "rust-analyzer"] From cbdfdf6e3ee8b24de4c380ebe4f7d1a1d32b2fdb Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 21 Sep 2024 16:46:45 +0800 Subject: [PATCH 2/2] fix compile Signed-off-by: tison --- src/format.rs | 21 +++++++-------------- src/tests.rs | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/format.rs b/src/format.rs index 3126426..e2d3f5b 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,13 +1,12 @@ 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::Facility; +use crate::get_hostname; +use crate::get_process_info; +use crate::Priority; #[allow(non_camel_case_types)] #[derive(Copy, Clone)] @@ -281,10 +280,7 @@ mod test { let d = Formatter3164::default(); // `Facility` doesn't implement `PartialEq`, so we use a `match` instead. - assert!(match d.facility { - Facility::LOG_USER => true, - _ => false, - }); + assert!(matches!(d.facility, Facility::LOG_USER)); assert!(match &d.hostname { Some(hostname) => !hostname.is_empty(), @@ -301,10 +297,7 @@ mod test { let d = Formatter5424::default(); // `Facility` doesn't implement `PartialEq`, so we use a `match` instead. - assert!(match d.facility { - Facility::LOG_USER => true, - _ => false, - }); + assert!(matches!(d.facility, Facility::LOG_USER)); assert!(match &d.hostname { Some(hostname) => !hostname.is_empty(), diff --git a/src/tests.rs b/src/tests.rs index 8b99ea1..17ffd8f 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,4 @@ -use io::Read; +use std::io::Read; use std::{collections::BTreeMap, sync::Barrier}; #[test] @@ -156,7 +156,7 @@ fn test_udp() { let mut counter = 0; while let Ok((sz, _)) = listener.recv_from(&mut buf) { - locked.push_str(&std::str::from_utf8(&buf[..sz]).unwrap()); + locked.push_str(std::str::from_utf8(&buf[..sz]).unwrap()); println!("string is now(sz={sz}): {locked}"); counter += 1;