mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-23 11:15:27 +00:00
big heckin reworkerino to use the standard #line directive as per spec
This commit is contained in:
parent
cb7c9b8b49
commit
d3365c3bff
52 changed files with 574 additions and 398 deletions
43
server/logging/src/lib.rs
Normal file
43
server/logging/src/lib.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use rand::{rngs, Rng};
|
||||
use slog::slog_o;
|
||||
use slog_scope::GlobalLoggerGuard;
|
||||
use slog_term::{FullFormat, PlainSyncDecorator};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
use std::io::Stderr;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use slog::*;
|
||||
use slog_atomic::*;
|
||||
|
||||
fn new_trace_id() -> String {
|
||||
let rng = CURRENT_RNG.with(|rng| rng.borrow_mut().gen::<[u8; 4]>());
|
||||
return format!("{:04x}", u32::from_be_bytes(rng));
|
||||
}
|
||||
|
||||
pub fn slog_with_trace_id<F: FnOnce()>(f: F) {
|
||||
slog_scope::scope(&slog_scope::logger().new(slog_o!("trace" => new_trace_id())), f)
|
||||
}
|
||||
|
||||
pub fn set_logger_with_level(level: Level) -> GlobalLoggerGuard {
|
||||
let drain = Arc::new(logger_base(level).fuse());
|
||||
DRAIN_SWITCH.ctrl().set(drain.clone());
|
||||
slog_scope::set_global_logger(Logger::root(drain, o!()))
|
||||
}
|
||||
|
||||
fn logger_base(level: Level) -> LevelFilter<Fuse<FullFormat<PlainSyncDecorator<Stderr>>>> {
|
||||
let plain = slog_term::PlainSyncDecorator::new(std::io::stderr());
|
||||
let drain = slog_term::FullFormat::new(plain).build().fuse();
|
||||
drain.filter_level(level)
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static CURRENT_RNG: RefCell<rngs::ThreadRng> = RefCell::new(rngs::ThreadRng::default());
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref DRAIN_SWITCH: AtomicSwitch<()> = {
|
||||
let logger = logger_base(Level::Info).fuse();
|
||||
AtomicSwitch::new(logger)
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue