Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tidy build and readme #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
42 changes: 10 additions & 32 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Geal/rust-syslog
slug: Geal/rust-syslog
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "syslog"
version = "7.0.0"
edition = "2021"
authors = [ "[email protected]" ]
description = "Syslog message formatter and writer, supporting unix sockets, UDP and TCP exporters"
license = "MIT"
Expand All @@ -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"] }
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -67,7 +61,6 @@ fn main() {

info!("hello world");
}

```

There are 3 functions to create loggers:
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["cargo", "rustfmt", "clippy", "rust-analyzer"]
21 changes: 7 additions & 14 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use io::Read;
use std::io::Read;
use std::{collections::BTreeMap, sync::Barrier};

#[test]
Expand Down Expand Up @@ -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;
Expand Down