Skip to content

Commit 60814b0

Browse files
add hierarchical layer
1 parent 850c239 commit 60814b0

File tree

7 files changed

+84
-11
lines changed

7 files changed

+84
-11
lines changed

Cargo.lock

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ strum = { version = "0.27.1", features = ["derive"] }
4444
sqlx = { version = "0.8.2", features = ["runtime-tokio", "runtime-async-std", "postgres", "json"] }
4545
syn = "1.0.109"
4646
termcolor = "1.4.1"
47-
test-log = "0.2.17"
47+
test-log = "0.2.17"
4848
tokio = { version = "1.40.0", features = ["full"] }
4949
tower-lsp = "0.20.0"
5050
tracing = { version = "0.1.40", default-features = false, features = ["std"] }

crates/pgt_cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ tracing = { workspace = true }
3939
tracing-appender = "0.2.3"
4040
tracing-bunyan-formatter = { workspace = true }
4141
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
42+
tracing-tree = { version = "0.4.0", features = ["time"] }
4243

4344
[target.'cfg(unix)'.dependencies]
4445
libc = "0.2.161"

crates/pgt_cli/src/commands/daemon.rs

+35-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tracing_subscriber::{
1717
prelude::*,
1818
registry,
1919
};
20+
use tracing_tree::{HierarchicalLayer, time::UtcDateTime};
2021

2122
pub(crate) fn start(
2223
session: CliSession,
@@ -78,8 +79,9 @@ pub(crate) fn run_server(
7879
log_path: Option<PathBuf>,
7980
log_file_name_prefix: Option<String>,
8081
log_level: Option<String>,
82+
log_kind: Option<String>,
8183
) -> Result<(), CliDiagnostic> {
82-
setup_tracing_subscriber(log_path, log_file_name_prefix, log_level);
84+
setup_tracing_subscriber(log_path, log_file_name_prefix, log_level, log_kind);
8385

8486
let rt = Runtime::new()?;
8587
let factory = ServerFactory::new(stop_on_disconnect);
@@ -185,6 +187,7 @@ fn setup_tracing_subscriber(
185187
log_path: Option<PathBuf>,
186188
log_file_name_prefix: Option<String>,
187189
log_level: Option<String>,
190+
log_kind: Option<String>,
188191
) {
189192
let pgt_log_path = log_path.unwrap_or(pgt_fs::ensure_cache_dir().join("pgt-logs"));
190193

@@ -197,13 +200,37 @@ fn setup_tracing_subscriber(
197200
.build(pgt_log_path)
198201
.expect("Failed to start the logger for the daemon.");
199202

200-
registry()
201-
.with(JsonStorageLayer)
202-
.with(
203-
BunyanFormattingLayer::new("pgt_logs".into(), file_appender)
204-
.with_filter(PgtLoggingFilter::from(log_level)),
205-
)
206-
.init();
203+
let filter = PgtLoggingFilter::from(log_level);
204+
205+
let log_kind = log_kind.unwrap_or("hierarchical".into());
206+
207+
match log_kind.as_str() {
208+
"bunyan" => {
209+
registry()
210+
.with(JsonStorageLayer)
211+
.with(
212+
BunyanFormattingLayer::new("pgt_logs".into(), file_appender)
213+
.with_filter(filter),
214+
)
215+
.init();
216+
}
217+
218+
_ => registry()
219+
.with(
220+
HierarchicalLayer::default()
221+
.with_indent_lines(true)
222+
.with_indent_amount(2)
223+
.with_bracketed_fields(true)
224+
.with_targets(true)
225+
.with_ansi(false)
226+
.with_timer(UtcDateTime {
227+
higher_precision: false,
228+
})
229+
.with_writer(file_appender)
230+
.with_filter(filter),
231+
)
232+
.init(),
233+
}
207234
}
208235

209236
pub fn default_pgt_log_path() -> PathBuf {

crates/pgt_cli/src/commands/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ pub enum PgtCommand {
171171
)]
172172
log_level: String,
173173

174+
/// Allows to change the logging format kind. Default is hierarchical.
175+
#[bpaf(
176+
env("PGT_LOG_KIND"),
177+
long("log-kind"),
178+
argument("hierarchical|bunyan"),
179+
fallback(String::from("hierarchical"))
180+
)]
181+
log_kind: String,
182+
174183
#[bpaf(long("stop-on-disconnect"), hide_usage)]
175184
stop_on_disconnect: bool,
176185
/// Allows to set a custom file path to the configuration file,

crates/pgt_cli/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ impl<'app> CliSession<'app> {
106106
log_path,
107107
log_prefix_name,
108108
log_level,
109+
log_kind,
109110
} => commands::daemon::run_server(
110111
stop_on_disconnect,
111112
config_path,
112113
Some(log_path),
113114
Some(log_prefix_name),
114115
Some(log_level),
116+
Some(log_kind),
115117
),
116118
PgtCommand::PrintSocket => commands::daemon::print_socket(),
117119
};

crates/pgt_lsp/src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl LanguageServer for LSPServer {
227227
async fn code_action(&self, params: CodeActionParams) -> LspResult<Option<CodeActionResponse>> {
228228
match handlers::code_actions::get_actions(&self.session, params) {
229229
Ok(result) => {
230-
tracing::info!("Got Code Actions: {:?}", result);
230+
tracing::trace!("Got {} Code Action(s)", result.len());
231231
return LspResult::Ok(Some(result));
232232
}
233233
Err(e) => LspResult::Err(into_lsp_error(e)),

0 commit comments

Comments
 (0)