feat(corp/rih/backend): sprinkle some logging all over the place
Change-Id: Ifd55a0bf75070b1d47c2d65c32960f05ad7040a0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8736 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
f72d1f459d
commit
75ffea3fe6
4 changed files with 100 additions and 10 deletions
47
corp/rih/backend/src/yandex_log.rs
Normal file
47
corp/rih/backend/src/yandex_log.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//! Implements a `log::Log` logger that adheres to the structure
|
||||
//! expected by Yandex Cloud Serverless logs.
|
||||
//!
|
||||
//! https://cloud.yandex.ru/docs/serverless-containers/concepts/logs
|
||||
|
||||
use log::{Level, Log};
|
||||
use serde_json::json;
|
||||
|
||||
pub struct YandexCloudLogger;
|
||||
|
||||
pub const YANDEX_CLOUD_LOGGER: YandexCloudLogger = YandexCloudLogger;
|
||||
|
||||
fn level_map(level: &Level) -> &'static str {
|
||||
match level {
|
||||
Level::Error => "ERROR",
|
||||
Level::Warn => "WARN",
|
||||
Level::Info => "INFO",
|
||||
Level::Debug => "DEBUG",
|
||||
Level::Trace => "TRACE",
|
||||
}
|
||||
}
|
||||
|
||||
impl Log for YandexCloudLogger {
|
||||
fn enabled(&self, _: &log::Metadata<'_>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record<'_>) {
|
||||
if !self.enabled(record.metadata()) {
|
||||
return;
|
||||
}
|
||||
|
||||
eprintln!(
|
||||
"{}",
|
||||
json!({
|
||||
"level": level_map(&record.level()),
|
||||
"message": record.args().to_string(),
|
||||
"target": record.target(),
|
||||
"module": record.module_path(),
|
||||
"file": record.file(),
|
||||
"line": record.line(),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue