mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 08:38:31 +00:00
The logging system has been brought to a fully functional level.
This commit is contained in:
19
Cargo.lock
generated
19
Cargo.lock
generated
@@ -221,13 +221,12 @@ dependencies = [
|
||||
name = "dcr"
|
||||
version = "0.9.1"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"ctrlc",
|
||||
"env_logger",
|
||||
"fatfs",
|
||||
"glob",
|
||||
"log",
|
||||
"paris-log",
|
||||
"owo-colors",
|
||||
"self-replace",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -748,20 +747,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
||||
|
||||
[[package]]
|
||||
name = "paris"
|
||||
version = "1.5.15"
|
||||
name = "owo-colors"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fecab3723493c7851f292cb060f3ee1c42f19b8d749345d0d7eaf3fd19aa62d"
|
||||
|
||||
[[package]]
|
||||
name = "paris-log"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "774dbe6c00feee96462fae6b32789d9f570569f0b1543cea61336932b240d7eb"
|
||||
dependencies = [
|
||||
"log",
|
||||
"paris",
|
||||
]
|
||||
checksum = "13c45bb4a6ae1280ec0803b1ef9d3455eb50f01efbbe1447ab020f1d54fba9d8"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
|
||||
@@ -78,8 +78,7 @@ fatfs = { version = "0.3", optional = true }
|
||||
#Logging
|
||||
log = "0.4.34"
|
||||
env_logger = "0.11.11"
|
||||
anstyle = "1.0.14"
|
||||
paris-log = "1" # Под влияние попадают все строки переданные в логирование, надо осторожно
|
||||
owo-colors = "4"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
|
||||
@@ -112,7 +112,7 @@ pub fn add(args: &[String]) -> i32 {
|
||||
let mut config = match Config::open(&root.join("dcr.toml").to_string_lossy()) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
error!("{}", &err.to_string());
|
||||
error!("{err}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -243,7 +243,7 @@ pub fn build(args: &[String]) -> i32 {
|
||||
}
|
||||
Err(err) => {
|
||||
common::finish_progress_line();
|
||||
error!("{}", &err.message);
|
||||
error!("{}", err.message);
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::utils::log;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod core;
|
||||
@@ -30,7 +29,7 @@ use prelude::*;
|
||||
/// appropriate subcommand handler. With fewer than two arguments, shows help and
|
||||
/// exits with code 0; otherwise exits with the handler's exit code.
|
||||
fn main() {
|
||||
log::init();
|
||||
utils::log::init();
|
||||
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub use paris_log::{error, warn};
|
||||
pub use log::{error, warn};
|
||||
// use owo_colors::OwoColorize;
|
||||
|
||||
@@ -15,34 +15,30 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use anstyle::{AnsiColor, Style};
|
||||
use env_logger::*;
|
||||
use log::*;
|
||||
use owo_colors::OwoColorize;
|
||||
use std::io::Write;
|
||||
|
||||
// Функция инициализирующая логирование
|
||||
pub fn init() {
|
||||
Builder::new()
|
||||
.filter_level(LevelFilter::Warn)
|
||||
.write_style(WriteStyle::Auto)
|
||||
.format(|buf, record| {
|
||||
let color = match record.level() {
|
||||
Level::Error => AnsiColor::Red,
|
||||
Level::Warn => AnsiColor::Yellow,
|
||||
Level::Info => AnsiColor::White,
|
||||
Level::Debug => AnsiColor::Magenta,
|
||||
Level::Trace => AnsiColor::BrightBlack,
|
||||
let colored_lv = match record.level() {
|
||||
Level::Error => record.level().red().to_string(),
|
||||
Level::Warn => record.level().yellow().to_string(),
|
||||
Level::Info => record.level().default_color().to_string(),
|
||||
_ => record.level().purple().italic().to_string(),
|
||||
};
|
||||
|
||||
let style = Style::new().fg_color(Some(color.into())).bold();
|
||||
|
||||
writeln!(
|
||||
buf,
|
||||
"{style}{}{style:#}: {}",
|
||||
record.level().to_string().to_lowercase(),
|
||||
"{}: {}",
|
||||
colored_lv.to_lowercase().bold(),
|
||||
record.args(),
|
||||
)
|
||||
})
|
||||
.init();
|
||||
|
||||
// env_logger::init(); // Уровень логирования из переменных окружения
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user