Move tracing initialization to server entry point
Refactored tracing initialization from lib.rs to server.rs, ensuring logging setup occurs only when the server starts. Updated README and docker-compose.yml to reflect new server startup command and options for authentication.
This commit is contained in:
1 parent
9e155493f0
commit
3ad7c6ac0f
4 files changed
+96
-52
No files matched your search
@@ -33,6 +33,43 @@
|
||||
|
||||
|
||||
## 📜 使用文档
|
||||
获取命令帮助 `biliup --help`
|
||||
```shell
|
||||
Upload video to bilibili.
|
||||
|
||||
Usage: biliup [OPTIONS] <COMMAND>
|
||||
|
||||
Commands:
|
||||
login 登录B站并保存登录信息
|
||||
renew 手动验证并刷新登录信息
|
||||
upload 上传视频
|
||||
append 是否要对某稿件追加视频
|
||||
show 打印视频详情
|
||||
dump-flv 输出flv元数据
|
||||
download 下载视频
|
||||
server 启动web服务,默认端口19159
|
||||
list 列出所有已上传的视频
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
Options:
|
||||
-p, --proxy <PROXY> 配置代理
|
||||
-u, --user-cookie <USER_COOKIE> 登录信息文件 [default: cookies.json]
|
||||
--rust-log <RUST_LOG> [default: tower_http=debug,info]
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
```
|
||||
启动录制服务
|
||||
```shell
|
||||
启动web服务,默认端口19159
|
||||
|
||||
Usage: biliup server [OPTIONS]
|
||||
|
||||
Options:
|
||||
-b, --bind <BIND> Specify bind address [default: 0.0.0.0]
|
||||
-p, --port <PORT> Port to use [default: 19159]
|
||||
-a, --auth Port to use
|
||||
-h, --help Print help
|
||||
```
|
||||
|
||||
- [使用文档 »](https://docs.biliup.rs)
|
||||
|
||||
@@ -44,7 +81,7 @@
|
||||
### Linux 或 macOS
|
||||
1. 安装 [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
||||
2. 安装:`uv tool install biliup`
|
||||
3. 启动:`biliup start`
|
||||
3. 启动:`biliup server --auth`
|
||||
4. 访问 WebUI:`http://your-ip:19159`
|
||||
|
||||
### Termux
|
||||
|
||||
@@ -41,54 +41,7 @@ static GUARD: Mutex<Option<tracing_appender::non_blocking::WorkerGuard>> = Mutex
|
||||
|
||||
fn init_tracing_with_rotation() {
|
||||
INIT.call_once(|| {
|
||||
let local_time = tracing_subscriber::fmt::time::LocalTime::new(format_description!(
|
||||
"[year]-[month]-[day] [hour]:[minute]:[second]"
|
||||
));
|
||||
// 按日期滚动,每天创建新文件
|
||||
let file_appender = tracing_appender::rolling::RollingFileAppender::builder()
|
||||
.rotation(Rotation::DAILY) // rotate log files once every hour
|
||||
.rotation(Rotation::NEVER) // rotate log files once every hour
|
||||
.filename_prefix("biliup") // log file names will be prefixed with `myapp.`
|
||||
.filename_prefix("download") // log file names will be prefixed with `myapp.`
|
||||
.filename_suffix("log") // log file names will be suffixed with `.log`
|
||||
// .max_log_files(3)
|
||||
// .build("logs") // try to build an appender that stores log files in `/var/log`
|
||||
.build("") // try to build an appender that stores log files in `/var/log`
|
||||
.expect("initializing rolling file appender failed");
|
||||
// 或者按小时滚动
|
||||
// let file_appender = tracing_appender::rolling::hourly("logs", "upload.log");
|
||||
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
// 保存 guard
|
||||
*GUARD.lock().unwrap() = Some(guard);
|
||||
|
||||
let subscriber = tracing_subscriber::registry()
|
||||
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
||||
// 控制台输出
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_target(false)
|
||||
.with_timer(local_time.clone())
|
||||
.with_file(true) // 打印文件名
|
||||
.with_line_number(true)
|
||||
.with_thread_ids(true),
|
||||
)
|
||||
// 文件输出
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_writer(non_blocking)
|
||||
.with_timer(local_time)
|
||||
.with_target(true)
|
||||
.with_thread_ids(true)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.with_ansi(false), // .json() // 可选:使用 JSON 格式便于解析
|
||||
);
|
||||
|
||||
subscriber.init();
|
||||
|
||||
info!("Tracing initialized with daily rotation");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use biliup_cli::server::infrastructure::repositories::get_upload_config;
|
||||
use biliup_cli::server::infrastructure::service_register::ServiceRegister;
|
||||
use biliup_cli::uploader::{append, list, login, renew, show, upload_by_command, upload_by_config};
|
||||
use chrono::Utc;
|
||||
use clap::Parser;
|
||||
use clap::{Error, Parser};
|
||||
use error_stack::{Report, ResultExt};
|
||||
use fancy_regex::Regex;
|
||||
use pyo3::prelude::PyDictMethods;
|
||||
@@ -36,7 +36,12 @@ use std::net::ToSocketAddrs;
|
||||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, LazyLock, RwLock};
|
||||
use time::macros::format_description;
|
||||
use tracing::{debug, info};
|
||||
use tracing_appender::rolling::Rotation;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PyPlugin {
|
||||
@@ -355,7 +360,56 @@ fn cfg_arc() -> &'static Arc<RwLock<Config>> {
|
||||
|
||||
#[tokio::main]
|
||||
pub(crate) async fn _main(args: &[String]) -> AppResult<()> {
|
||||
let cli = Cli::try_parse_from(args).change_context(AppError::Unknown)?;
|
||||
let cli = match Cli::try_parse_from(args) {
|
||||
Ok(res) => res,
|
||||
Err(e) => e.exit(),
|
||||
};
|
||||
|
||||
let local_time = tracing_subscriber::fmt::time::LocalTime::new(format_description!(
|
||||
"[year]-[month]-[day] [hour]:[minute]:[second]"
|
||||
));
|
||||
// 按日期滚动,每天创建新文件
|
||||
let file_appender = tracing_appender::rolling::RollingFileAppender::builder()
|
||||
.rotation(Rotation::DAILY) // rotate log files once every hour
|
||||
.rotation(Rotation::NEVER) // rotate log files once every hour
|
||||
.filename_prefix("biliup") // log file names will be prefixed with `myapp.`
|
||||
.filename_prefix("download") // log file names will be prefixed with `myapp.`
|
||||
.filename_suffix("log") // log file names will be suffixed with `.log`
|
||||
// .max_log_files(3)
|
||||
// .build("logs") // try to build an appender that stores log files in `/var/log`
|
||||
.build("") // try to build an appender that stores log files in `/var/log`
|
||||
.expect("initializing rolling file appender failed");
|
||||
// 或者按小时滚动
|
||||
// let file_appender = tracing_appender::rolling::hourly("logs", "upload.log");
|
||||
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
let subscriber = tracing_subscriber::registry()
|
||||
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
||||
// 控制台输出
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_target(false)
|
||||
.with_timer(local_time.clone())
|
||||
.with_file(true) // 打印文件名
|
||||
.with_line_number(true)
|
||||
.with_thread_ids(true),
|
||||
)
|
||||
// 文件输出
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_writer(non_blocking)
|
||||
.with_timer(local_time)
|
||||
.with_target(true)
|
||||
.with_thread_ids(true)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.with_ansi(false), // .json() // 可选:使用 JSON 格式便于解析
|
||||
);
|
||||
|
||||
let _ = subscriber.init();
|
||||
|
||||
info!("Tracing initialized with daily rotation");
|
||||
|
||||
match cli.command {
|
||||
Commands::Login => login(cli.user_cookie, cli.proxy.as_deref()).await?,
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ services:
|
||||
- "<HOST_ADDRESS>:<HOST_PORT>:19159"
|
||||
volumes:
|
||||
- /path/to/save_folder:/opt
|
||||
command: --password <your_password>
|
||||
command: server --auth
|
||||
Reference in new issue
Block a user