mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
refactor: remove proc-macro support and replace timed_println with tracing info logs
This commit is contained in:
Generated
-3
@@ -5431,13 +5431,11 @@ dependencies = [
|
|||||||
"mime_guess",
|
"mime_guess",
|
||||||
"netif",
|
"netif",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"proc-macro2",
|
|
||||||
"prost",
|
"prost",
|
||||||
"prost-build",
|
"prost-build",
|
||||||
"prost-types",
|
"prost-types",
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"protos",
|
"protos",
|
||||||
"quote",
|
|
||||||
"rmp-serde",
|
"rmp-serde",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"s3s",
|
"s3s",
|
||||||
@@ -5445,7 +5443,6 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"shadow-rs",
|
"shadow-rs",
|
||||||
"syn 2.0.98",
|
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ rust-version.workspace = true
|
|||||||
name = "rustfs"
|
name = "rustfs"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
# 添加proc-macro库声明
|
|
||||||
[lib]
|
|
||||||
name = "rustfs_macro"
|
|
||||||
path = "src/macro/mod.rs"
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
@@ -82,10 +76,6 @@ mime_guess = "2.0.5"
|
|||||||
rust-embed = { version = "8.6.0", features = ["interpolate-folder-path"] }
|
rust-embed = { version = "8.6.0", features = ["interpolate-folder-path"] }
|
||||||
local-ip-address = "0.6.3"
|
local-ip-address = "0.6.3"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
# 添加proc-macro所需依赖
|
|
||||||
proc-macro2 = "1.0"
|
|
||||||
quote = "1.0"
|
|
||||||
syn = { version = "2.0", features = ["full"] }
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build.workspace = true
|
prost-build.workspace = true
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ use axum::{
|
|||||||
|
|
||||||
use mime_guess::from_path;
|
use mime_guess::from_path;
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use rustfs_macro::timed_println;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use shadow_rs::shadow;
|
use shadow_rs::shadow;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
shadow!(build);
|
shadow!(build);
|
||||||
|
|
||||||
@@ -162,14 +162,14 @@ pub async fn start_static_file_server(addrs: &str, local_ip: Ipv4Addr, access_ke
|
|||||||
let listener = tokio::net::TcpListener::bind(addrs).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(addrs).await.unwrap();
|
||||||
let local_addr = listener.local_addr().unwrap();
|
let local_addr = listener.local_addr().unwrap();
|
||||||
|
|
||||||
timed_println!(format!(
|
info!(
|
||||||
"WebUI: http://{}:{} http://127.0.0.1:{}",
|
"WebUI: http://{}:{} http://127.0.0.1:{}",
|
||||||
local_ip,
|
local_ip,
|
||||||
local_addr.port(),
|
local_addr.port(),
|
||||||
local_addr.port()
|
local_addr.port()
|
||||||
));
|
);
|
||||||
timed_println!(format!(" RootUser: {}", access_key));
|
info!(" RootUser: {}", access_key);
|
||||||
timed_println!(format!(" RootPass: {}", secret_key));
|
info!(" RootPass: {}", secret_key);
|
||||||
|
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
use proc_macro::TokenStream;
|
|
||||||
use quote::quote;
|
|
||||||
use syn::{parse_macro_input, Expr, LitStr};
|
|
||||||
|
|
||||||
#[proc_macro]
|
|
||||||
pub fn timed_println(input: TokenStream) -> TokenStream {
|
|
||||||
// 解析输入
|
|
||||||
let expr = parse_macro_input!(input as Expr);
|
|
||||||
|
|
||||||
// 生成带有时间戳的打印代码
|
|
||||||
let expanded = quote! {
|
|
||||||
{
|
|
||||||
let now = chrono::Utc::now();
|
|
||||||
let timestamp = now.format("%Y-%m-%dT%H:%M:%S.%6fZ");
|
|
||||||
println!("{} rustfs: {}", timestamp, #expr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[proc_macro]
|
|
||||||
pub fn timed_println_str(input: TokenStream) -> TokenStream {
|
|
||||||
// 尝试将输入解析为字符串字面量
|
|
||||||
let input_str = parse_macro_input!(input as LitStr);
|
|
||||||
let str_value = input_str.value();
|
|
||||||
|
|
||||||
// 生成带有时间戳的打印代码
|
|
||||||
let expanded = quote! {
|
|
||||||
{
|
|
||||||
let now = chrono::Utc::now();
|
|
||||||
let timestamp = now.format("%Y-%m-%dT%H:%M:%S.%6fZ");
|
|
||||||
println!("{} rustfs: {}", timestamp, #str_value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
+12
-18
@@ -7,15 +7,10 @@ mod service;
|
|||||||
mod storage;
|
mod storage;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
// 导入过程宏
|
|
||||||
extern crate rustfs_macro;
|
|
||||||
use rustfs_macro::timed_println;
|
|
||||||
use tracing::Level;
|
|
||||||
|
|
||||||
use crate::auth::IAMAuth;
|
use crate::auth::IAMAuth;
|
||||||
use crate::console::{init_console_cfg, CONSOLE_CONFIG};
|
use crate::console::{init_console_cfg, CONSOLE_CONFIG};
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use clap::{builder, Parser};
|
use clap::Parser;
|
||||||
use common::{
|
use common::{
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
globals::set_global_addr,
|
globals::set_global_addr,
|
||||||
@@ -45,7 +40,7 @@ use std::{io::IsTerminal, net::SocketAddr};
|
|||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tonic::{metadata::MetadataValue, Request, Status};
|
use tonic::{metadata::MetadataValue, Request, Status};
|
||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn, event, span};
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, Layer};
|
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, Layer};
|
||||||
|
|
||||||
@@ -59,7 +54,6 @@ fn setup_tracing() {
|
|||||||
.pretty()
|
.pretty()
|
||||||
.with_env_filter(env_filter)
|
.with_env_filter(env_filter)
|
||||||
.with_ansi(enable_color)
|
.with_ansi(enable_color)
|
||||||
// Remove file and line number information from log output
|
|
||||||
.with_file(true)
|
.with_file(true)
|
||||||
.with_line_number(true)
|
.with_line_number(true)
|
||||||
.finish()
|
.finish()
|
||||||
@@ -81,12 +75,12 @@ fn print_server_info() {
|
|||||||
let cfg = CONSOLE_CONFIG.get().unwrap();
|
let cfg = CONSOLE_CONFIG.get().unwrap();
|
||||||
let current_year = chrono::Utc::now().year();
|
let current_year = chrono::Utc::now().year();
|
||||||
|
|
||||||
// 使用过程宏打印服务器信息
|
// 使用自定义宏打印服务器信息
|
||||||
timed_println!("RustFS Object Storage Server");
|
info!("RustFS Object Storage Server");
|
||||||
timed_println!(format!("Copyright: 2024-{} RustFS, Inc", current_year));
|
info!("Copyright: 2024-{} RustFS, Inc", current_year);
|
||||||
timed_println!(format!("License: {}", cfg.license()));
|
info!("License: {}", cfg.license());
|
||||||
timed_println!(format!("Version: {}", cfg.version()));
|
info!("Version: {}", cfg.version());
|
||||||
timed_println!(format!("Docs: {}", cfg.doc()));
|
info!("Docs: {}", cfg.doc());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@@ -149,9 +143,9 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
// Detailed endpoint information (showing all API endpoints)
|
// Detailed endpoint information (showing all API endpoints)
|
||||||
let api_endpoints = format!("http://{}:{}", local_ip, server_port);
|
let api_endpoints = format!("http://{}:{}", local_ip, server_port);
|
||||||
let localhost_endpoint = format!("http://127.0.0.1:{}", server_port);
|
let localhost_endpoint = format!("http://127.0.0.1:{}", server_port);
|
||||||
timed_println!(format!("API: {} {}", api_endpoints, localhost_endpoint));
|
info!("API: {} {}", api_endpoints, localhost_endpoint);
|
||||||
timed_println!(format!(" RootUser: {}", opt.access_key.clone()));
|
info!(" RootUser: {}", opt.access_key.clone());
|
||||||
timed_println!(format!(" RootPass: {}", opt.secret_key.clone()));
|
info!(" RootPass: {}", opt.secret_key.clone());
|
||||||
if DEFAULT_ACCESS_KEY.eq(&opt.access_key) && DEFAULT_SECRET_KEY.eq(&opt.secret_key) {
|
if DEFAULT_ACCESS_KEY.eq(&opt.access_key) && DEFAULT_SECRET_KEY.eq(&opt.secret_key) {
|
||||||
warn!("Detected default credentials '{}:{}', we recommend that you change these values with 'RUSTFS_ACCESS_KEY' and 'RUSTFS_SECRET_KEY' environment variables", DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY);
|
warn!("Detected default credentials '{}:{}', we recommend that you change these values with 'RUSTFS_ACCESS_KEY' and 'RUSTFS_SECRET_KEY' environment variables", DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY);
|
||||||
}
|
}
|
||||||
@@ -191,7 +185,7 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
|
|
||||||
b.set_route(admin::make_admin_route()?);
|
b.set_route(admin::make_admin_route()?);
|
||||||
|
|
||||||
if !opt.server_domains.is_empty() {
|
if (!opt.server_domains.is_empty()) {
|
||||||
info!("virtual-hosted-style requests are enabled use domain_name {:?}", &opt.server_domains);
|
info!("virtual-hosted-style requests are enabled use domain_name {:?}", &opt.server_domains);
|
||||||
b.set_host(MultiDomain::new(&opt.server_domains)?);
|
b.set_host(MultiDomain::new(&opt.server_domains)?);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user