-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hubble): add json logging (#1927)
Adds the CLI option to set logging to json format, as well as updated the service with the log-format parameter. Also made log-format an enum in unionvisor to make it less error prone.
- Loading branch information
Showing
6 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::str::FromStr; | ||
|
||
use thiserror::Error; | ||
use tracing_subscriber::EnvFilter; | ||
|
||
pub fn init(log_format: LogFormat) { | ||
match log_format { | ||
LogFormat::Plain => { | ||
tracing_subscriber::fmt() | ||
.with_env_filter(EnvFilter::from_default_env()) | ||
.init(); | ||
} | ||
LogFormat::Json => { | ||
tracing_subscriber::fmt() | ||
.with_env_filter(EnvFilter::from_default_env()) | ||
.json() | ||
.init(); | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum LogFormat { | ||
Plain, | ||
Json, | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
#[error("unknown log format {0}")] | ||
pub struct UnknownLogFormatError(String); | ||
|
||
impl FromStr for LogFormat { | ||
type Err = UnknownLogFormatError; | ||
|
||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { | ||
match s { | ||
"plain" => Ok(Self::Plain), | ||
"json" => Ok(Self::Json), | ||
s => Err(UnknownLogFormatError(s.to_owned())), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters