encore/telemetry/log.rs
1//! Encore integrations for the standard `log` facade.
2
3/// A direct Encore console logger for the standard [`::log`] facade.
4/// Does not initialize the runtime or install globals. The application
5/// installs it explicitly and sets its own maximum level:
6///
7/// ```no_run
8/// encore::log::set_logger(encore::telemetry::log::logger())?;
9/// encore::log::set_max_level(encore::log::LevelFilter::Info);
10/// encore::log::info!(count = 3u64; "finished");
11/// encore::telemetry::log::flush();
12/// # Ok::<(), encore::log::SetLoggerError>(())
13/// ```
14///
15/// Preserves typed key-values, source metadata and the current native OTel
16/// context. Uses the same filters, queue and bounded flush as
17/// [`crate::telemetry::tracing::logs_layer`]. Internal tracing diagnostics are
18/// excluded; native resource spans and metrics work independently. Choose
19/// this direct logger or `tracing_log::LogTracer`, not both.
20pub fn logger() -> &'static dyn ::log::Log {
21 crate::console_log::logger()
22}
23
24/// Waits up to one second for Encore's queued console events to be written.
25/// Does not initialize the runtime. Call before exit when using [`logger`] or
26/// [`crate::telemetry::tracing::logs_layer`] standalone; runtime shutdown
27/// flushes automatically. Queue overflow or blocked output may still lose events.
28pub fn flush() {
29 crate::console_log::flush();
30}