Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoLittle committed Sep 19, 2022
1 parent 1276976 commit ee749af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atri_qq"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
authors = ["LaoLittle"]
description = "AtriQQ"
Expand Down
16 changes: 11 additions & 5 deletions src/service/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;
use std::io::Write;

use crate::terminal::{INPUT_BUFFER, PROMPT};
use tracing::{error, Level};
use tracing::{warn, Level};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::fmt::time::OffsetTime;
use tracing_subscriber::fmt::writer::MakeWriterExt;
Expand All @@ -17,12 +17,15 @@ pub fn init_logger() -> (WorkerGuard, WorkerGuard) {

let (s, s_guard) = tracing_appender::non_blocking(LogStdoutWriter);

let stdout_layer = tracing_subscriber::fmt::layer().with_writer(s.with_max_level(Level::DEBUG));
let stdout_layer = tracing_subscriber::fmt::layer()
.with_target(false)
.with_writer(s.with_max_level(Level::DEBUG));

let file_writer = tracing_appender::rolling::daily("log", "atri_qq.log");
let (f, f_guard) = tracing_appender::non_blocking(file_writer);

let file_layer = tracing_subscriber::fmt::layer()
.with_target(false)
.with_ansi(false)
.with_writer(f.with_max_level(Level::DEBUG));

Expand All @@ -32,15 +35,18 @@ pub fn init_logger() -> (WorkerGuard, WorkerGuard) {
};

let timer = OffsetTime::new(offset, time_format);
let (stdout_layer, file_layer) = (stdout_layer.with_timer(timer.clone()), file_layer.with_timer(timer));
let (stdout_layer, file_layer) = (
stdout_layer.with_timer(timer.clone()),
file_layer.with_timer(timer),
);

tracing_subscriber::registry()
.with(stdout_layer)
.with(file_layer)
.init();

if let Some(e) = err {
error!("初始化日志时间错误: {}, 使用默认时区UTC+8", e);
warn!("初始化日志时间错误: {}, 使用默认时区UTC+8", e);
}

(s_guard, f_guard)
Expand Down Expand Up @@ -71,4 +77,4 @@ impl Write for LogStdoutWriter {
fn flush(&mut self) -> io::Result<()> {
io::stdout().flush()
}
}
}

0 comments on commit ee749af

Please sign in to comment.