Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Change Log

## 0.9.20

- The language server logs will now be in local time of whatever machine they are running on, rather than UTC.

## 0.9.19
- Added configuration option to control the max cache size while resolving references in semantic analysis, defaulting to 500MB
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ clap = { version = "4.2", features = ["cargo", "derive"] }
crossbeam = "0.8"
crossbeam-deque = "0.8.1"
crossbeam-utils = "0.8.7"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
env_logger = "0.11"
hashlink = "0.12"
itertools = "0.14"
Expand Down
29 changes: 29 additions & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// © 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0 and MIT

use std::io::Write;
use std::sync::LazyLock;

use chrono::Local;

macro_rules! info {
($($arg:tt)*) => {
crate::log_with_fn!(log::info, log::Level::Info, $($arg)*)
Expand Down Expand Up @@ -73,10 +76,36 @@ pub fn init() {
let max_level = dummy_logger.filter();
env_logger::Builder::from_default_env()
.filter_level(log::LevelFilter::Trace)
.format(local_time_format)
.init();
set_global_log_level(max_level);
}

/// Replicates `env_logger`'s default record format, except the timestamp is
/// rendered in the system's local time zone
fn local_time_format(
buf: &mut env_logger::fmt::Formatter,
record: &log::Record<'_>,
) -> std::io::Result<()> {
// ISO 8601 with seconds precision (env_logger's default), but local time
// with the local UTC offset instead of the "Z" suffix.
let ts = Local::now().format("%Y-%m-%dT%H:%M:%S%:z");
let level = record.level();
let style = buf.default_level_style(level);
// Formatting 'style' normally enables it, doing it with :# disables it
write!(buf, "[{ts} {style}{level:<5}{style:#}")?;
let target = record.target();
if !target.is_empty() {
write!(buf, " {target}")?;
}
let msg = record.args().to_string();
if msg.contains('\n') {
writeln!(buf, "] {}", msg.replace('\n', "\n "))
} else {
writeln!(buf, "] {msg}")
}
}

pub fn set_global_log_level(level: log::LevelFilter) {
log::set_max_level(level);
}
Expand Down
Loading