relay_utils/
initialize.rs1use parking_lot::Mutex;
20use sp_tracing::{
21 tracing::Level,
22 tracing_subscriber::{
23 fmt::{time::OffsetTime, SubscriberBuilder},
24 EnvFilter,
25 },
26};
27use std::cell::RefCell;
28
29pub static RELAYER_VERSION: Mutex<Option<String>> = Mutex::new(None);
32
33async_std::task_local! {
34 pub(crate) static LOOP_NAME: RefCell<String> = RefCell::new(String::default());
35}
36
37pub fn initialize_relay() {
39 initialize_logger(true);
40}
41
42pub fn initialize_logger(with_timestamp: bool) {
44 let format = time::format_description::parse(
45 "[year]-[month]-[day] \
46 [hour repr:24]:[minute]:[second] [offset_hour sign:mandatory]",
47 )
48 .expect("static format string is valid");
49
50 let local_time = OffsetTime::new(
51 time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC),
52 format,
53 );
54
55 let env_filter = EnvFilter::builder()
56 .with_default_directive(Level::WARN.into())
57 .with_default_directive("bridge=info".parse().expect("static filter string is valid"))
58 .from_env_lossy();
59
60 let builder = SubscriberBuilder::default().with_env_filter(env_filter);
61
62 if with_timestamp {
63 builder.with_timer(local_time).init();
64 } else {
65 builder.without_time().init();
66 }
67}
68
69pub(crate) fn initialize_loop(loop_name: String) {
71 LOOP_NAME.with(|g_loop_name| *g_loop_name.borrow_mut() = loop_name);
72}