Compare commits
1 Commits
pythonplus
...
tracing-in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f16822c56 |
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -783,15 +783,6 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
|
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fern"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.22"
|
version = "0.2.22"
|
||||||
@@ -2030,7 +2021,6 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"colored",
|
"colored",
|
||||||
"fern",
|
|
||||||
"glob",
|
"glob",
|
||||||
"globset",
|
"globset",
|
||||||
"imperative",
|
"imperative",
|
||||||
@@ -2080,6 +2070,8 @@ dependencies = [
|
|||||||
"test-case",
|
"test-case",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"toml",
|
"toml",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
"typed-arena",
|
"typed-arena",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"unicode_names2",
|
"unicode_names2",
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ bitflags = { workspace = true }
|
|||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
clap = { workspace = true, features = ["derive", "string"], optional = true }
|
clap = { workspace = true, features = ["derive", "string"], optional = true }
|
||||||
colored = { workspace = true }
|
colored = { workspace = true }
|
||||||
fern = { version = "0.6.1" }
|
|
||||||
glob = { workspace = true }
|
glob = { workspace = true }
|
||||||
globset = { workspace = true }
|
globset = { workspace = true }
|
||||||
imperative = { version = "1.0.4" }
|
imperative = { version = "1.0.4" }
|
||||||
@@ -71,6 +70,8 @@ strum = { workspace = true }
|
|||||||
strum_macros = { workspace = true }
|
strum_macros = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
toml = { workspace = true }
|
toml = { workspace = true }
|
||||||
|
tracing = { workspace = true }
|
||||||
|
tracing-subscriber = { workspace = true }
|
||||||
typed-arena = { version = "2.0.2" }
|
typed-arena = { version = "2.0.2" }
|
||||||
unicode-width = { workspace = true }
|
unicode-width = { workspace = true }
|
||||||
unicode_names2 = { version = "0.6.0", git = "https://github.com/youknowone/unicode_names2.git", rev = "4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" }
|
unicode_names2 = { version = "0.6.0", git = "https://github.com/youknowone/unicode_names2.git", rev = "4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" }
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ use std::sync::Mutex;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use fern;
|
|
||||||
use log::Level;
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use ruff_python_parser::{ParseError, ParseErrorType};
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use ruff_notebook::Notebook;
|
||||||
|
use ruff_python_parser::{ParseError, ParseErrorType};
|
||||||
use ruff_source_file::{OneIndexed, SourceCode, SourceLocation};
|
use ruff_source_file::{OneIndexed, SourceCode, SourceLocation};
|
||||||
|
|
||||||
use crate::fs;
|
use crate::fs;
|
||||||
use crate::source_kind::SourceKind;
|
use crate::source_kind::SourceKind;
|
||||||
use ruff_notebook::Notebook;
|
|
||||||
|
|
||||||
pub static WARNINGS: Lazy<Mutex<Vec<&'static str>>> = Lazy::new(Mutex::default);
|
pub static WARNINGS: Lazy<Mutex<Vec<&'static str>>> = Lazy::new(Mutex::default);
|
||||||
|
|
||||||
@@ -90,49 +91,27 @@ pub enum LogLevel {
|
|||||||
|
|
||||||
impl LogLevel {
|
impl LogLevel {
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
const fn level_filter(&self) -> log::LevelFilter {
|
const fn tracing_level(&self) -> tracing::Level {
|
||||||
match self {
|
match self {
|
||||||
LogLevel::Default => log::LevelFilter::Info,
|
LogLevel::Default => tracing::Level::INFO,
|
||||||
LogLevel::Verbose => log::LevelFilter::Debug,
|
LogLevel::Verbose => tracing::Level::DEBUG,
|
||||||
LogLevel::Quiet => log::LevelFilter::Off,
|
LogLevel::Quiet => tracing::Level::WARN,
|
||||||
LogLevel::Silent => log::LevelFilter::Off,
|
LogLevel::Silent => tracing::Level::ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Log level priorities: 1. `RUST_LOG=`, 2. explicit CLI log level, 3. default to info
|
||||||
pub fn set_up_logging(level: &LogLevel) -> Result<()> {
|
pub fn set_up_logging(level: &LogLevel) -> Result<()> {
|
||||||
fern::Dispatch::new()
|
let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
||||||
.format(|out, message, record| match record.level() {
|
EnvFilter::builder()
|
||||||
Level::Error => {
|
.with_default_directive(level.tracing_level().into())
|
||||||
out.finish(format_args!(
|
.parse_lossy("")
|
||||||
"{}{} {}",
|
});
|
||||||
"error".red().bold(),
|
tracing_subscriber::registry()
|
||||||
":".bold(),
|
.with(filter_layer)
|
||||||
message
|
.with(tracing_subscriber::fmt::layer())
|
||||||
));
|
.init();
|
||||||
}
|
|
||||||
Level::Warn => {
|
|
||||||
out.finish(format_args!(
|
|
||||||
"{}{} {}",
|
|
||||||
"warning".yellow().bold(),
|
|
||||||
":".bold(),
|
|
||||||
message
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Level::Info | Level::Debug | Level::Trace => {
|
|
||||||
out.finish(format_args!(
|
|
||||||
"{}[{}][{}] {}",
|
|
||||||
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
|
||||||
record.target(),
|
|
||||||
record.level(),
|
|
||||||
message
|
|
||||||
));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.level(level.level_filter())
|
|
||||||
.level_for("globset", log::LevelFilter::Warn)
|
|
||||||
.chain(std::io::stderr())
|
|
||||||
.apply()?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ shellexpand = { workspace = true }
|
|||||||
similar = { workspace = true }
|
similar = { workspace = true }
|
||||||
strum = { workspace = true, features = [] }
|
strum = { workspace = true, features = [] }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
tracing = { workspace = true, features = ["log"] }
|
tracing = { workspace = true }
|
||||||
walkdir = { version = "2.3.2" }
|
walkdir = { version = "2.3.2" }
|
||||||
wild = { version = "2" }
|
wild = { version = "2" }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user