generated from PlexSheep/baserepo
Compare commits
No commits in common. "a7d0c18f52889293813ead01e84f591e840f7be9" and "895b156e0290c18d665fd807c56706f54291fd23" have entirely different histories.
a7d0c18f52
...
895b156e02
6 changed files with 100 additions and 67 deletions
|
@ -5,7 +5,7 @@ default-members = [".", "members/libpt-core"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
publish = true
|
publish = true
|
||||||
version = "0.7.3-alpha.1"
|
version = "0.7.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -21,8 +21,8 @@ anyhow = "1.0.79"
|
||||||
thiserror = "1.0.56"
|
thiserror = "1.0.56"
|
||||||
libpt-core = { version = "0.5.0", path = "members/libpt-core" }
|
libpt-core = { version = "0.5.0", path = "members/libpt-core" }
|
||||||
libpt-bintols = { version = "0.5.1", path = "members/libpt-bintols" }
|
libpt-bintols = { version = "0.5.1", path = "members/libpt-bintols" }
|
||||||
libpt-log = { version = "0.6.2-alpha.1", path = "members/libpt-log" }
|
libpt-log = { version = "0.6.1", path = "members/libpt-log" }
|
||||||
libpt-cli = { version = "0.2.2-alpha.1", path = "members/libpt-cli" }
|
libpt-cli = { version = "0.2.1", path = "members/libpt-cli" }
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libpt-cli"
|
name = "libpt-cli"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
version = "0.2.2-alpha.1"
|
version = "0.2.1"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
@ -24,6 +24,8 @@ comfy-table = "7.1.1"
|
||||||
console = "0.15.8"
|
console = "0.15.8"
|
||||||
dialoguer = { version = "0.11.0", features = ["completion", "history"] }
|
dialoguer = { version = "0.11.0", features = ["completion", "history"] }
|
||||||
embed-doc-image = "0.1.4"
|
embed-doc-image = "0.1.4"
|
||||||
|
exitcode = "1.1.2"
|
||||||
|
human-panic = "2.0.0"
|
||||||
indicatif = "0.17.8"
|
indicatif = "0.17.8"
|
||||||
libpt-log = { workspace = true, optional = false }
|
libpt-log = { workspace = true, optional = false }
|
||||||
log = { version = "0.4.21", optional = true }
|
log = { version = "0.4.21", optional = true }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libpt-log"
|
name = "libpt-log"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
version = "0.6.2-alpha.1"
|
version = "0.6.1"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
@ -13,13 +13,12 @@ keywords.workspace = true
|
||||||
categories.workspace = true
|
categories.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.37"
|
||||||
tracing-appender = "0.2.3"
|
tracing-appender = "0.2.2"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = "0.3.17"
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
libpt-core = { workspace = true, optional = false }
|
libpt-core = { workspace = true, optional = false }
|
||||||
chrono = "0.4.38"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gag = "1.0.0"
|
gag = "1.0.0"
|
||||||
|
|
|
@ -20,6 +20,4 @@ pub enum Error {
|
||||||
/// any other error type, wrapped in [`anyhow::Error`]
|
/// any other error type, wrapped in [`anyhow::Error`]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Other(#[from] anyhow::Error),
|
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)]
|
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Debug},
|
fmt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
@ -31,9 +31,8 @@ use error::Error;
|
||||||
/// I'm just repackaging it a little to make it more ergonomic
|
/// I'm just repackaging it a little to make it more ergonomic
|
||||||
pub use tracing;
|
pub use tracing;
|
||||||
pub use tracing::{debug, error, info, trace, warn, Level};
|
pub use tracing::{debug, error, info, trace, warn, Level};
|
||||||
use tracing_subscriber::{
|
use tracing_appender::{self};
|
||||||
fmt::format::FmtSpan, layer::SubscriberExt as _, util::SubscriberInitExt, Layer,
|
use tracing_subscriber::fmt::{format::FmtSpan, time};
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
/// The log level used when none is specified
|
/// The log level used when none is specified
|
||||||
|
@ -131,72 +130,100 @@ impl LoggerBuilder {
|
||||||
/// This function will return an error if a global Logger was aready initialized. This module
|
/// 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,
|
/// uses the [tracing] crate for logging, so if a [tracing] logger is initialized elsewhere,
|
||||||
/// this method will error.
|
/// this method will error.
|
||||||
#[allow(clippy::missing_panics_doc)]
|
|
||||||
pub fn build(self) -> Result<Logger> {
|
pub fn build(self) -> Result<Logger> {
|
||||||
// only init if no init has been performed yet
|
// only init if no init has been performed yet
|
||||||
if INITIALIZED.load(Ordering::Relaxed) {
|
if INITIALIZED.load(Ordering::Relaxed) {
|
||||||
warn!("trying to reinitialize the logger, ignoring");
|
warn!("trying to reinitialize the logger, ignoring");
|
||||||
bail!(Error::Usage("logging is already initialized".to_string()));
|
bail!(Error::Usage("logging is already initialized".to_string()));
|
||||||
}
|
}
|
||||||
let layer = tracing_subscriber::fmt::layer()
|
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
||||||
|
.with_level(self.display_level)
|
||||||
|
.with_max_level(self.max_level)
|
||||||
.with_ansi(self.ansi)
|
.with_ansi(self.ansi)
|
||||||
.with_target(self.display_target)
|
.with_target(self.display_target)
|
||||||
.with_file(self.display_filename)
|
.with_file(self.display_filename)
|
||||||
.with_thread_ids(self.display_thread_ids)
|
.with_thread_ids(self.display_thread_ids)
|
||||||
.with_line_number(self.display_line_number)
|
.with_line_number(self.display_line_number)
|
||||||
.with_thread_names(self.display_thread_names)
|
.with_thread_names(self.display_thread_names)
|
||||||
.with_span_events(self.span_events.clone())
|
.with_span_events(self.span_events);
|
||||||
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
// HACK: somehow find a better solution for this
|
||||||
self.max_level,
|
// 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
|
||||||
if self.log_to_file {
|
// type is changed every time. When using `Box<dyn Whatever>`, some methods complain about
|
||||||
tracing_subscriber::registry()
|
// not being in trait bounds.
|
||||||
.with(layer.and_then({
|
match (self.log_to_file, self.show_time, self.pretty, self.uptime) {
|
||||||
tracing_subscriber::fmt::layer()
|
(true, true, true, true) => {
|
||||||
.with_writer(
|
let subscriber = subscriber
|
||||||
self.logfile()?
|
.with_writer(new_file_appender(self.log_dir))
|
||||||
.expect("logging to file is requested but logfile returned None"),
|
.with_timer(time::uptime())
|
||||||
)
|
.pretty()
|
||||||
.with_ansi(self.ansi)
|
.finish();
|
||||||
.with_target(self.display_target)
|
tracing::subscriber::set_global_default(subscriber)?;
|
||||||
.with_file(self.display_filename)
|
}
|
||||||
.with_thread_ids(self.display_thread_ids)
|
(true, true, true, false) => {
|
||||||
.with_line_number(self.display_line_number)
|
let subscriber = subscriber
|
||||||
.with_thread_names(self.display_thread_names)
|
.with_writer(new_file_appender(self.log_dir))
|
||||||
.with_span_events(self.span_events.clone())
|
.pretty()
|
||||||
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
.finish();
|
||||||
self.max_level,
|
tracing::subscriber::set_global_default(subscriber)?;
|
||||||
))
|
}
|
||||||
}))
|
(true, false, true, _) => {
|
||||||
.init();
|
let subscriber = subscriber
|
||||||
} else {
|
.with_writer(new_file_appender(self.log_dir))
|
||||||
tracing_subscriber::registry().with(layer).init();
|
.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)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INITIALIZED.store(true, Ordering::Relaxed);
|
INITIALIZED.store(true, Ordering::Relaxed);
|
||||||
Ok(Logger {})
|
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
|
/// 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`]!
|
/// If you want to log to a file, don't forget to set [`Self::log_dir`]!
|
||||||
|
@ -463,3 +490,13 @@ impl Default for Logger {
|
||||||
.expect("building a Logger failed")
|
.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,9 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
cargo check --all-features --workspace
|
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')
|
|
||||||
echo ">>>>>>>> PUBLISHING RELEASE FOR REPO"
|
echo ">>>>>>>> PUBLISHING RELEASE FOR REPO"
|
||||||
bash scripts/release.sh
|
bash scripts/release.sh
|
||||||
echo ">>>>>>>> PUBLISHING TO CRATES.IO NEXT"
|
echo ">>>>>>>> PUBLISHING TO CRATES.IO NEXT"
|
||||||
|
|
Reference in a new issue