mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
feat(gateway): add option for outputting logs as JSON (#10620)
To enable customers to ingest flow logs (#8353) into various SIEMS, outputting structured logs is crucial.
This commit is contained in:
@@ -22,7 +22,7 @@ use phoenix_channel::get_user_agent;
|
||||
|
||||
use phoenix_channel::PhoenixChannel;
|
||||
use secrecy::{Secret, SecretString};
|
||||
use std::{collections::BTreeSet, path::Path};
|
||||
use std::{collections::BTreeSet, fmt, path::Path};
|
||||
use std::{path::PathBuf, process::ExitCode};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tracing_subscriber::layer;
|
||||
@@ -91,8 +91,14 @@ fn has_necessary_permissions() -> bool {
|
||||
}
|
||||
|
||||
async fn try_main(cli: Cli, telemetry: &mut Telemetry) -> Result<()> {
|
||||
firezone_logging::setup_global_subscriber(layer::Identity::default())
|
||||
.context("Failed to set up logging")?;
|
||||
firezone_logging::setup_global_subscriber(
|
||||
layer::Identity::default(),
|
||||
match cli.log_format {
|
||||
LogFormat::Json => true,
|
||||
LogFormat::Human => false,
|
||||
},
|
||||
)
|
||||
.context("Failed to set up logging")?;
|
||||
|
||||
tracing::info!(
|
||||
arch = std::env::consts::ARCH,
|
||||
@@ -306,6 +312,9 @@ struct Cli {
|
||||
#[arg(short = 'i', long, env = "FIREZONE_ID")]
|
||||
firezone_id: Option<String>,
|
||||
|
||||
#[arg(long, env = "FIREZONE_LOG_FORMAT", default_value_t = LogFormat::Human)]
|
||||
log_format: LogFormat,
|
||||
|
||||
/// Where to export metrics to.
|
||||
///
|
||||
/// This configuration option is private API and has no stability guarantees.
|
||||
@@ -336,6 +345,21 @@ struct Cli {
|
||||
no_inc_buf: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
|
||||
enum LogFormat {
|
||||
Json,
|
||||
Human,
|
||||
}
|
||||
|
||||
impl fmt::Display for LogFormat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
LogFormat::Json => write!(f, "json"),
|
||||
LogFormat::Human => write!(f, "human"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
|
||||
enum MetricsExporter {
|
||||
Stdout,
|
||||
|
||||
Reference in New Issue
Block a user