Add dynamic log level configuration support
Introduces a new `loggers_level` field in the server config to allow dynamic adjustment of log levels via the API and UI. Updates the developer UI to reflect the new log level controls and ensures the backend applies changes to the logging filter at runtime. Also bumps the version to 1.1.27.
This commit is contained in:
1 parent
07da196a9d
commit
c172efb6cd
6 files changed
+29
-12
No files matched your search
Generated
+2
-2
@@ -362,7 +362,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "biliup-cli"
|
||||
version = "1.1.26"
|
||||
version = "1.1.27"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-trait",
|
||||
@@ -3693,7 +3693,7 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||
|
||||
[[package]]
|
||||
name = "stream-gears"
|
||||
version = "1.1.26"
|
||||
version = "1.1.27"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-trait",
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ members = [
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "1.1.26"
|
||||
version = "1.1.27"
|
||||
|
||||
[workspace.dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
@@ -40,7 +40,7 @@ const Developer: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<Form.Select
|
||||
label=" 控制台日志输出等级(LOGGING.root.level)"
|
||||
label=" ds_update.log 日志输出等级(LOGGING.root.level, LOGGING.loggers.biliup.level)"
|
||||
field="LOGGING.root.level"
|
||||
placeholder={'INFO'}
|
||||
style={{ width: '100%' }}
|
||||
@@ -48,8 +48,10 @@ const Developer: React.FC = () => {
|
||||
alignSelf: 'stretch',
|
||||
padding: 0,
|
||||
}}
|
||||
onChange={() => {
|
||||
onChange={(value) => {
|
||||
formApi.setValue('LOGGING.root.handlers', ['console'])
|
||||
formApi.setValue('LOGGING.loggers.biliup.handlers', ['file'])
|
||||
formApi.setValue('LOGGING.loggers.biliup.level', value)
|
||||
}}
|
||||
showClear={true}
|
||||
>
|
||||
@@ -60,8 +62,8 @@ const Developer: React.FC = () => {
|
||||
<Select.Option value="CRITICAL">CRITICAL</Select.Option>
|
||||
</Form.Select>
|
||||
<Form.Select
|
||||
label=" 文件日志输出等级(LOGGING.loggers.biliup.level)"
|
||||
field="LOGGING.loggers.biliup.level"
|
||||
label=" 文件日志输出等级(download.log)"
|
||||
field="loggers_level"
|
||||
placeholder={'INFO'}
|
||||
style={{ width: '100%' }}
|
||||
fieldStyle={{
|
||||
@@ -69,7 +71,6 @@ const Developer: React.FC = () => {
|
||||
padding: 0,
|
||||
}}
|
||||
onChange={() => {
|
||||
formApi.setValue('LOGGING.loggers.biliup.handlers', ['file'])
|
||||
}}
|
||||
showClear={true}
|
||||
>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::UploadLine;
|
||||
use crate::server::common::upload::{build_studio, submit_to_bilibili, upload};
|
||||
use crate::server::common::util::Recorder;
|
||||
use crate::server::config::Config;
|
||||
@@ -18,6 +17,7 @@ use crate::server::infrastructure::repositories::{
|
||||
del_streamer, get_all_streamer, get_upload_config,
|
||||
};
|
||||
use crate::server::infrastructure::service_register::ServiceRegister;
|
||||
use crate::{LogHandle, UploadLine};
|
||||
use axum::Json;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::http::StatusCode;
|
||||
@@ -35,6 +35,7 @@ use std::time::{Duration, UNIX_EPOCH};
|
||||
use tokio::fs;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
pub async fn get_streamers_endpoint(
|
||||
State(pool): State<ConnectionPool>,
|
||||
@@ -182,6 +183,7 @@ pub async fn get_configuration(
|
||||
pub async fn put_configuration(
|
||||
State(config): State<Arc<RwLock<Config>>>,
|
||||
State(pool): State<ConnectionPool>,
|
||||
State(log_handle): State<LogHandle>,
|
||||
Json(json_data): Json<Config>,
|
||||
) -> Result<Json<Config>, Response> {
|
||||
// 将 JSON 序列化为 TEXT 存库
|
||||
@@ -260,7 +262,19 @@ pub async fn put_configuration(
|
||||
.change_context(AppError::Unknown)
|
||||
.map_err(report_to_response)?;
|
||||
*config.write().unwrap() = saved_config;
|
||||
Ok(Json(config.read().unwrap().clone()))
|
||||
let guard = config.read().unwrap();
|
||||
if let Some(loggers_level) = &guard.loggers_level {
|
||||
let new_filter = EnvFilter::try_new(loggers_level)
|
||||
.change_context(AppError::Custom(String::from("Invalid log level format")))
|
||||
.map_err(report_to_response)?;
|
||||
|
||||
log_handle
|
||||
.modify(|filter| *filter = new_filter)
|
||||
.change_context(AppError::Unknown)
|
||||
.map_err(report_to_response)?;
|
||||
}
|
||||
|
||||
Ok(Json(guard.clone()))
|
||||
}
|
||||
|
||||
pub async fn get_streamer_info(
|
||||
|
||||
@@ -215,6 +215,8 @@ pub struct Config {
|
||||
/// 用户Cookie配置
|
||||
#[serde(default)]
|
||||
pub user: Option<UserConfig>,
|
||||
|
||||
pub loggers_level: Option<String>,
|
||||
}
|
||||
|
||||
/// 主播配置结构体
|
||||
|
||||
@@ -25,8 +25,8 @@ pub struct ServiceRegister {
|
||||
pub config: Arc<RwLock<Config>>,
|
||||
/// HTTP客户端
|
||||
pub client: StatelessClient,
|
||||
#[from_ref(skip)]
|
||||
log_handle: LogHandle,
|
||||
|
||||
pub log_handle: LogHandle,
|
||||
}
|
||||
|
||||
/// 简单的服务容器,负责管理API端点通过axum扩展获取的各种服务
|
||||
|
||||
Reference in new issue
Block a user