generated from PlexSheep/baserepo
Compare commits
15 Commits
Author | SHA1 | Date |
---|---|---|
Christoph J. Scherr | 11a2d7908e | |
Christoph J. Scherr | 90e3442b50 | |
Christoph J. Scherr | 30168c5523 | |
Christoph J. Scherr | a7d0c18f52 | |
Christoph J. Scherr | 54a694645f | |
Christoph J. Scherr | 492e655d29 | |
Christoph J. Scherr | a9fbcf9518 | |
Christoph J. Scherr | 51e2c3029e | |
Christoph J. Scherr | 6197532bc7 | |
Christoph J. Scherr | 3063f77798 | |
Christoph J. Scherr | 05910ae3be | |
PlexSheep | 895b156e02 | |
Christoph J. Scherr | 35ab3d9b28 | |
Christoph J. Scherr | 917a68c8ab | |
Christoph J. Scherr | 5b0c82cf2b |
|
@ -21,8 +21,6 @@ jobs:
|
|||
run: |
|
||||
rustup component add rustfmt
|
||||
rustup component add clippy
|
||||
- name: install python
|
||||
run: apt update && apt install libpython3-dev -y
|
||||
- name: config custom registry
|
||||
run: |
|
||||
mkdir -p ~/.cargo/
|
||||
|
@ -45,4 +43,4 @@ jobs:
|
|||
with:
|
||||
# Optional. Commit message for the created commit.
|
||||
# Defaults to "Apply automatic changes"
|
||||
commit_message: automatic cargo CI changes
|
||||
commit_message: "ci: automatic cargo CI changes"
|
|
@ -0,0 +1,7 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
# Check for updates every Monday
|
||||
schedule:
|
||||
interval: "weekly"
|
|
@ -1,10 +1,16 @@
|
|||
name: cargo devel CI
|
||||
name: Rust CI
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '**'
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
# - '!master'
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
CI:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -42,10 +48,10 @@ jobs:
|
|||
- name: cargo fmt
|
||||
run: cargo fmt --all
|
||||
- name: cargo test
|
||||
run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc
|
||||
run: cargo test --all-features --all-targets --workspace
|
||||
- name: commit back to repository
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
# Optional. Commit message for the created commit.
|
||||
# Defaults to "Apply automatic changes"
|
||||
commit_message: automatic cargo CI changes
|
||||
commit_message: "ci: automatic Rust CI changes"
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
name: Release-plz
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
|
||||
# Release unpublished packages.
|
||||
release-plz-release:
|
||||
name: Release-plz release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- name: Run release-plz
|
||||
uses: MarcoIeni/release-plz-action@v0.5
|
||||
with:
|
||||
command: release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
# Create a PR with the new versions and changelog, preparing the next release.
|
||||
release-plz-pr:
|
||||
name: Release-plz PR
|
||||
runs-on: ubuntu-latest
|
||||
concurrency:
|
||||
group: release-plz-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- name: Run release-plz
|
||||
uses: MarcoIeni/release-plz-action@v0.5
|
||||
with:
|
||||
command: release-pr
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
@ -5,7 +5,7 @@ default-members = [".", "members/libpt-core"]
|
|||
|
||||
[workspace.package]
|
||||
publish = true
|
||||
version = "0.7.1"
|
||||
version = "0.7.3-alpha.2"
|
||||
edition = "2021"
|
||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
|
@ -21,8 +21,8 @@ anyhow = "1.0.79"
|
|||
thiserror = "1.0.56"
|
||||
libpt-core = { version = "0.5.0", path = "members/libpt-core" }
|
||||
libpt-bintols = { version = "0.5.1", path = "members/libpt-bintols" }
|
||||
libpt-log = { version = "0.6.0", path = "members/libpt-log" }
|
||||
libpt-cli = { version = "0.2.1", path = "members/libpt-cli" }
|
||||
libpt-log = { version = "0.6.2-alpha.1", path = "members/libpt-log" }
|
||||
libpt-cli = { version = "0.2.2-alpha.1", path = "members/libpt-cli" }
|
||||
|
||||
[package]
|
||||
name = "libpt"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "libpt-cli"
|
||||
publish.workspace = true
|
||||
version = "0.2.1"
|
||||
version = "0.2.2-alpha.2"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -24,8 +24,6 @@ comfy-table = "7.1.1"
|
|||
console = "0.15.8"
|
||||
dialoguer = { version = "0.11.0", features = ["completion", "history"] }
|
||||
embed-doc-image = "0.1.4"
|
||||
exitcode = "1.1.2"
|
||||
human-panic = "2.0.0"
|
||||
indicatif = "0.17.8"
|
||||
libpt-log = { workspace = true, optional = false }
|
||||
log = { version = "0.4.21", optional = true }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "libpt-log"
|
||||
publish.workspace = true
|
||||
version = "0.6.0"
|
||||
version = "0.6.2-alpha.2"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -13,12 +13,13 @@ keywords.workspace = true
|
|||
categories.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1.37"
|
||||
tracing-appender = "0.2.2"
|
||||
tracing-subscriber = "0.3.17"
|
||||
tracing = "0.1.40"
|
||||
tracing-appender = "0.2.3"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
anyhow = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
libpt-core = { workspace = true, optional = false }
|
||||
chrono = "0.4.38"
|
||||
|
||||
[dev-dependencies]
|
||||
gag = "1.0.0"
|
||||
|
|
|
@ -17,7 +17,9 @@ pub enum Error {
|
|||
/// Could not assign logger as the global default
|
||||
#[error("Could not assign logger as global default")]
|
||||
SetGlobalDefaultFail(#[from] SetGlobalDefaultError),
|
||||
/// any other error type, wrapped in [anyhow::Error](anyhow::Error)
|
||||
/// any other error type, wrapped in [`anyhow::Error`]
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
#[error("Tried to open the logfile, but logging to file was not requested")]
|
||||
LogfileButNoFilelog,
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
|
||||
|
||||
use std::{
|
||||
fmt,
|
||||
fmt::{self, Debug},
|
||||
path::PathBuf,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
@ -31,8 +31,9 @@ use error::Error;
|
|||
/// I'm just repackaging it a little to make it more ergonomic
|
||||
pub use tracing;
|
||||
pub use tracing::{debug, error, info, trace, warn, Level};
|
||||
use tracing_appender::{self};
|
||||
use tracing_subscriber::fmt::{format::FmtSpan, time};
|
||||
use tracing_subscriber::{
|
||||
fmt::format::FmtSpan, layer::SubscriberExt as _, util::SubscriberInitExt, Layer,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
/// The log level used when none is specified
|
||||
|
@ -61,7 +62,7 @@ static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
|||
/// # }
|
||||
///
|
||||
/// ```
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[allow(clippy::struct_excessive_bools)] // it's just true/false values, not states, and I don't
|
||||
// need to reinvent the wheel
|
||||
pub struct LoggerBuilder {
|
||||
|
@ -94,6 +95,8 @@ pub struct LoggerBuilder {
|
|||
show_time: bool,
|
||||
/// show timestamps as uptime (duration since the logger was initialized)
|
||||
uptime: bool,
|
||||
/// log when span things happen
|
||||
span_events: FmtSpan,
|
||||
}
|
||||
|
||||
impl LoggerBuilder {
|
||||
|
@ -128,100 +131,72 @@ impl LoggerBuilder {
|
|||
/// This function will return an error if a global Logger was aready initialized. This module
|
||||
/// uses the [tracing] crate for logging, so if a [tracing] logger is initialized elsewhere,
|
||||
/// this method will error.
|
||||
#[allow(clippy::missing_panics_doc)]
|
||||
pub fn build(self) -> Result<Logger> {
|
||||
// only init if no init has been performed yet
|
||||
if INITIALIZED.load(Ordering::Relaxed) {
|
||||
warn!("trying to reinitialize the logger, ignoring");
|
||||
bail!(Error::Usage("logging is already initialized".to_string()));
|
||||
}
|
||||
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_level(self.display_level)
|
||||
.with_max_level(self.max_level)
|
||||
let layer = tracing_subscriber::fmt::layer()
|
||||
.with_ansi(self.ansi)
|
||||
.with_target(self.display_target)
|
||||
.with_file(self.display_filename)
|
||||
.with_thread_ids(self.display_thread_ids)
|
||||
.with_line_number(self.display_line_number)
|
||||
.with_thread_names(self.display_thread_names)
|
||||
.with_span_events(FmtSpan::FULL);
|
||||
// HACK: somehow find a better solution for this
|
||||
// I know this is hacky, but I couldn't get it any other way. I couldn't even find a
|
||||
// project that could do it any other way. You can't apply one after another, because the
|
||||
// type is changed every time. When using `Box<dyn Whatever>`, some methods complain about
|
||||
// not being in trait bounds.
|
||||
match (self.log_to_file, self.show_time, self.pretty, self.uptime) {
|
||||
(true, true, true, true) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.with_timer(time::uptime())
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, true, false) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, false, true, _) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.without_time()
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, false, true) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.with_timer(time::uptime())
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, false, false) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, false, false, _) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(self.log_dir))
|
||||
.without_time()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, true, true) => {
|
||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, true, false) => {
|
||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, false, true, _) => {
|
||||
let subscriber = subscriber.without_time().pretty().finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, false, true) => {
|
||||
let subscriber = subscriber.with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, false, false) => {
|
||||
let subscriber = subscriber.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, false, false, _) => {
|
||||
let subscriber = subscriber.without_time().finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
.with_span_events(self.span_events.clone())
|
||||
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
||||
self.max_level,
|
||||
));
|
||||
if self.log_to_file {
|
||||
tracing_subscriber::registry()
|
||||
.with(layer.and_then({
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_writer(
|
||||
self.logfile()?
|
||||
.expect("logging to file is requested but logfile returned None"),
|
||||
)
|
||||
.with_ansi(self.ansi)
|
||||
.with_target(self.display_target)
|
||||
.with_file(self.display_filename)
|
||||
.with_thread_ids(self.display_thread_ids)
|
||||
.with_line_number(self.display_line_number)
|
||||
.with_thread_names(self.display_thread_names)
|
||||
.with_span_events(self.span_events.clone())
|
||||
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
||||
self.max_level,
|
||||
))
|
||||
}))
|
||||
.init();
|
||||
} else {
|
||||
tracing_subscriber::registry().with(layer).init();
|
||||
}
|
||||
|
||||
INITIALIZED.store(true, Ordering::Relaxed);
|
||||
Ok(Logger {})
|
||||
}
|
||||
|
||||
/// Opens a new file for logging to.
|
||||
///
|
||||
/// Format: `{log_dir}/{consumer_name}_2024-09-01.log`
|
||||
///
|
||||
/// Will be none if [`Self::log_to_file`] is [false].
|
||||
fn logfile(&self) -> Result<Option<std::fs::File>> {
|
||||
if !self.log_to_file {
|
||||
return Err(Error::LogfileButNoFilelog.into());
|
||||
}
|
||||
let mut path = self.log_dir.clone();
|
||||
std::fs::create_dir_all(&path)?;
|
||||
path.push(format!(
|
||||
"{}_{}.log",
|
||||
libpt_core::get_crate_name().unwrap_or_else(|| "logfile".to_string()),
|
||||
chrono::Local::now().date_naive()
|
||||
));
|
||||
let file = std::fs::File::create(path)?;
|
||||
Ok(Some(file))
|
||||
}
|
||||
|
||||
/// enable or disable logging to and creating of logfiles
|
||||
///
|
||||
/// If you want to log to a file, don't forget to set [`Self::log_dir`]!
|
||||
|
@ -347,6 +322,15 @@ impl LoggerBuilder {
|
|||
self.max_level = max_level;
|
||||
self
|
||||
}
|
||||
|
||||
/// set how span events are handled
|
||||
///
|
||||
/// Default: [`FmtSpan::NONE`]
|
||||
#[must_use]
|
||||
pub const fn span_events(mut self, span_events: FmtSpan) -> Self {
|
||||
self.span_events = span_events;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LoggerBuilder {
|
||||
|
@ -365,11 +349,12 @@ impl Default for LoggerBuilder {
|
|||
pretty: false,
|
||||
show_time: true,
|
||||
uptime: false,
|
||||
span_events: FmtSpan::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Logger for [`pt`](libpt)
|
||||
/// ## Logger for `libpt`
|
||||
///
|
||||
/// A logger is generally a functionality that let's you write information from your library or
|
||||
/// application in a more structured manner than if you just wrote all information to `stdout` or
|
||||
|
@ -478,13 +463,3 @@ impl Default for Logger {
|
|||
.expect("building a Logger failed")
|
||||
}
|
||||
}
|
||||
|
||||
fn new_file_appender(log_dir: PathBuf) -> tracing_appender::rolling::RollingFileAppender {
|
||||
tracing_appender::rolling::daily(
|
||||
log_dir,
|
||||
format!(
|
||||
"{}.log",
|
||||
libpt_core::get_crate_name().unwrap_or_else(|| "logfile".to_string())
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
cargo check --all-features
|
||||
cargo check --all-features --workspace
|
||||
echo ">>>>>>>> SELECT A NEW VERSION"
|
||||
cargo ws version
|
||||
NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1')
|
||||
|
|
Reference in New Issue