Crates.io | quantum_log |
lib.rs | quantum_log |
version | 0.3.2 |
created_at | 2025-08-16 07:46:35.075592+00 |
updated_at | 2025-08-26 04:37:08.149796+00 |
description | High-performance asynchronous logging framework based on tracing ecosystem |
homepage | |
repository | https://github.com/Kirky-X/quantum_log |
max_upload_size | |
id | 1798085 |
size | 667,610 |
QuantumLog 是一个为高性能计算场景打造的异步日志库,支持文件、标准输出、数据库等多种输出目标,提供灵活的配置选项、优雅的关闭机制以及详细的诊断能力。
在你的 Cargo.toml
中添加依赖:
[dependencies]
quantum_log = "0.3.2"
tokio = { version = "1.0", features = ["full"] }
tracing = "0.1"
# 可选特性(示例)
[dependencies.quantum_log]
version = "0.3.2"
features = ["database", "mpi_support", "tls"] # 启用数据库、MPI 和 TLS 支持
use quantum_log::{init, shutdown};
use tracing::{info, warn, error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 初始化 QuantumLog
init().await?;
// 使用标准 tracing 宏
info!("应用启动");
warn!("这是一个警告");
error!("这是一个错误");
// 优雅关闭
shutdown().await?;
Ok(())
}
use quantum_log::init_quantum_logger;
use tracing::{info, warn, error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 使用带关闭句柄的初始化 API,适用于需要精确控制关闭时机的场景
let shutdown_handle = init_quantum_logger().await?;
info!("正在使用 QuantumLog 记录日志");
warn!("警告信息");
error!("错误信息");
// 使用返回的句柄优雅关闭
shutdown_handle.shutdown().await?;
Ok(())
}
init()
: 简单初始化,适用于大多数应用场景,使用全局 shutdown()
函数关闭init_quantum_logger()
: 返回关闭句柄,适用于需要精确控制关闭时机的场景init_with_config()
: 使用自定义配置初始化,适用于需要特定配置的场景QuantumLog 0.3.2 带来更强大的功能与更好的稳定性,主要变更:
📊 InfluxDB 时序数据库支持
🏗️ 项目架构重构
examples
crate
test/
和 examples/
目录,提升代码组织性.gitignore
,排除构建产物和设计文档🧪 测试框架改进
🔒 安全加固
⚡ 性能优化
🛠️ 代码质量改进
tls_verify_certificates
、tls_verify_hostname
、tls_ca_file
、tls_cert_file
、tls_key_file
max_reconnect_attempts
、reconnect_delay_ms
迁移提示(MPI 动态加载):自 0.3.2 起,运行时代码不再读取自定义
MPI_LIB_PATH
。请使用平台标准环境变量(LD_LIBRARY_PATH
/PATH
/DYLD_LIBRARY_PATH
)覆盖或指定库路径。MPI_LIB_PATH
仅在构建阶段作为信息展示,运行时不依赖该变量。
QuantumLog 支持在运行时动态加载 MPI 库,无需在编译期进行静态/动态链接。启用方式:
[dependencies.quantum_log]
version = "0.3.0"
features = ["mpi_support", "dynamic_mpi"]
亮点:
libmpi.so
, libmpi.so.12
, libmpi.so.40
mpi.dll
libmpi.dylib
示例:
use quantum_log::init_quantum_logger;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let handle = init_quantum_logger().await?;
tracing::info!("程序已启动;MPI 支持由运行时环境决定");
handle.shutdown().await?;
Ok(())
}
库查找配置: 系统按以下顺序查找 MPI 动态库:
LD_LIBRARY_PATH
(Linux)、PATH
(Windows)、DYLD_LIBRARY_PATH
(macOS)/usr/lib/x86_64-linux-gnu/openmpi/lib
/usr/lib64/openmpi/lib
/opt/intel/oneapi/mpi/latest/lib
/usr/local/lib
如需指定自定义库路径,请配置相应的系统环境变量。
注意:使用动态加载时,请确保目标系统已安装兼容的 MPI 运行时。
环境变量与路径覆盖:
MPI_LIB_PATH
运行时变量。export LD_LIBRARY_PATH=/path/to/mpi/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/path/to/mpi/lib:$DYLD_LIBRARY_PATH
$env:PATH = "C:\\Path\\to\\MPI\\bin;" + $env:PATH
MPI_LIB_PATH
输出构建环境信息,但运行时不依赖该变量。平台指引:
sudo apt-get install libopenmpi-dev openmpi-bin
或 sudo apt-get install mpich
sudo yum install openmpi openmpi-devel
或 sudo yum install mpich
mpi.dll
的目录在 PATH
中C:\\Program Files\\Microsoft MPI\\Bin
brew install open-mpi
,并在必要时将 $(brew --prefix)/lib
加入 DYLD_LIBRARY_PATH
运行测试:
# 运行全部测试
cargo test
# 按特性运行测试
cargo test --features database
cargo test --features mpi_support
cargo test --features tls
# 运行示例
cargo run --example basic_usage
cargo run --example complete_examples
cargo run --example config_file_example
cargo run --example influxdb_example
QuantumLog 支持将日志写入 InfluxDB,适用于需要时序数据分析的场景。
# InfluxDB 配置
[influxdb]
enabled = true
level = "INFO"
url = "http://localhost:8086"
database = "quantum_logs"
# 对于 InfluxDB 2.x,使用 token 认证
# token = "your-influxdb-token"
# 对于 InfluxDB 1.x,使用用户名/密码认证
username = "quantum_user"
password = "quantum_password"
batch_size = 100
flush_interval_seconds = 5
use_https = false
verify_ssl = true
日志数据在 InfluxDB 中的存储结构:
level
: 日志级别hostname
: 主机名thread
: 线程名mpi_rank
: MPI 排名(如果启用)message
: 日志消息file
: 文件路径line
: 行号module
: 模块路径username
: 用户名本项目基于 Apache-2.0 许可证发布。详见 LICENSE。
欢迎贡献!请阅读 CONTRIBUTING.md 了解如何参与项目开发。
如果你遇到问题或有建议,请: