A logging toolbox used by taosdata services written in the Rust language.
A tracing_subscriber Layer implementation,used when initializing the global tracing subscriber.
- Customize a type that implements the
QidManager
trait.
use taoslog::QidManager;
#[derive(Clone)]
pub(crate) struct Qid(u64);
impl QidManager for Qid {
fn init() -> Self {
Self(9223372036854775807)
}
fn get(&self) -> u64 {
self.0
}
}
impl From<u64> for Qid {
fn from(value: u64) -> Self {
Self(value)
}
}
- Init the global subscriber
use taoslog::writer::RollingFileAppender;
let appender = RollingFileAppender::builder("/var/log/taos", "taosx", 16)
.compress(true)
.reserved_disk_size("1GB")
.rotation_count(3)
.rotation_size("1GB")
.build()
.unwrap();
tracing_subscriber::registry()
.with(TaosLayer::<Qid>::new(appender))
.try_init()
.unwrap();
A RootSpanBuilder implementation, used in the actix-web framework to generate a new tracing span when receiving a new HTTP request.
use tracing_actix_web::TracingLogger;
use taoslog::middleware::TaosRootSpanBuilder;
let server = HttpServer::new(move || {
App::new()
.wrap(Compat::new(TracingLogger::<TaosRootSpanBuilder>::new()))
})
.bind(addr)
.unwrap()
.run();
let qid = Qid::from(12345);
// for tracing span
use taoslog::utils::Span;
tracing::info_span!("outer", "k" = "kkk").in_scope(|| {
Span.set_qid(qid);
let qid: Qid = Span.get_qid().unwrap();
});
// for http header
let mut headers = HeaderMap::new();
headers.set_qid(qid.clone());
let qid: Qid = headers.get_qid().unwrap();
// for RecordBatch Schema
let mut schema = Schema::empty();
schema.set_qid(qid.clone());
let qid: Qid = schema.get_qid().unwrap();