feat(global) better logging, add several fields for get_post api

- add sub_title, category, header_img to `get_post`
This commit is contained in:
lumither committed 2024-07-01 17:21:28 +08:00
1 parent 371f3cab39
commit d982bf0548
7 files changed
+194 -75

No files matched your search

+2 -7
View File
@@ -1,14 +1,13 @@
use std::{env, io};
use chrono::Local;
use tracing::{error, info, Level};
use tracing::info;
use tracing_appender::{non_blocking, rolling};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, Registry};
use tracing_subscriber::fmt::format::Writer;
use tracing_subscriber::fmt::MakeWriter;
use tracing_subscriber::fmt::time::FormatTime;
use tracing_subscriber::fmt::writer::MakeWriterExt;
use tracing_subscriber::layer::SubscriberExt;
use crate::constants::GLOBAL_TIME_FORMAT;
@@ -21,7 +20,7 @@ impl FormatTime for LocalTimer {
}
}
type LogWriter = dyn for<'writer> MakeWriter<'writer, Writer = dyn io::Write + 'static> + 'static;
type _LogWriter = dyn for<'writer> MakeWriter<'writer, Writer = dyn io::Write + 'static> + 'static;
pub fn init() -> (WorkerGuard, WorkerGuard) {
let log_path = env::var("LOG_ROOT_DIR").unwrap_or_else(|e| {
@@ -31,10 +30,8 @@ pub fn init() -> (WorkerGuard, WorkerGuard) {
let log_path = format!("{}/backend", log_path);
let (info_log_writer, info_guard) = non_blocking(rolling::never(&log_path, "info.log"));
// let info_log = info_log.with_max_level(Level::TRACE);
let (err_log_writer, error_guard) = non_blocking(rolling::never(&log_path, "error.log"));
// let error_log = error_logging_handle.with_filter(|log| log.level().eq(&Level::ERROR));
let log_format = tracing_subscriber::fmt::format()
.with_level(true)
@@ -42,12 +39,10 @@ pub fn init() -> (WorkerGuard, WorkerGuard) {
.with_source_location(true)
.with_timer(LocalTimer);
// todo: separate errors/warnings/info logs
let subscribers = Registry::default()
.with(
fmt::Layer::default()
.with_writer(info_log_writer)
// .with_max_level(Level::TRACE)
.with_ansi(false),
)
.with(