gateway_common/
log.rs

1use std::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4use tracing_appender::rolling::{RollingFileAppender, Rotation};
5
6#[derive(Debug, Serialize, Deserialize)]
7pub struct LogConfig {
8    pub name: String,
9    pub level: String,
10    pub path: String,
11}
12
13pub fn init_log(log_config: &LogConfig) {
14    let file_appender =
15        RollingFileAppender::new(Rotation::DAILY, &log_config.path, &log_config.name);
16    tracing_subscriber::fmt()
17        .json()
18        .with_max_level(tracing::Level::from_str(&log_config.level).expect("logging init error"))
19        .with_writer(file_appender)
20        .with_line_number(true)
21        .with_thread_ids(true)
22        .init();
23}
24
25pub fn get_uuid() -> String {
26    uuid::Uuid::new_v4().to_string()
27}