Add --json-log flag to enable structured JSON logging (#19968)
Co-authored-by: github_username <github_email> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
github_username
Claude Opus 4.6
parent
41fd53fe37
commit
e58391dd7d
@@ -354,6 +354,7 @@ struct Router {
|
|||||||
api_key: Option<String>,
|
api_key: Option<String>,
|
||||||
log_dir: Option<String>,
|
log_dir: Option<String>,
|
||||||
log_level: Option<String>,
|
log_level: Option<String>,
|
||||||
|
json_log: bool,
|
||||||
service_discovery: bool,
|
service_discovery: bool,
|
||||||
selector: HashMap<String, String>,
|
selector: HashMap<String, String>,
|
||||||
service_discovery_port: u16,
|
service_discovery_port: u16,
|
||||||
@@ -657,6 +658,7 @@ impl Router {
|
|||||||
api_key = None,
|
api_key = None,
|
||||||
log_dir = None,
|
log_dir = None,
|
||||||
log_level = None,
|
log_level = None,
|
||||||
|
json_log = false,
|
||||||
service_discovery = false,
|
service_discovery = false,
|
||||||
selector = HashMap::new(),
|
selector = HashMap::new(),
|
||||||
service_discovery_port = 80,
|
service_discovery_port = 80,
|
||||||
@@ -743,6 +745,7 @@ impl Router {
|
|||||||
api_key: Option<String>,
|
api_key: Option<String>,
|
||||||
log_dir: Option<String>,
|
log_dir: Option<String>,
|
||||||
log_level: Option<String>,
|
log_level: Option<String>,
|
||||||
|
json_log: bool,
|
||||||
service_discovery: bool,
|
service_discovery: bool,
|
||||||
selector: HashMap<String, String>,
|
selector: HashMap<String, String>,
|
||||||
service_discovery_port: u16,
|
service_discovery_port: u16,
|
||||||
@@ -842,6 +845,7 @@ impl Router {
|
|||||||
api_key,
|
api_key,
|
||||||
log_dir,
|
log_dir,
|
||||||
log_level,
|
log_level,
|
||||||
|
json_log,
|
||||||
service_discovery,
|
service_discovery,
|
||||||
selector,
|
selector,
|
||||||
service_discovery_port,
|
service_discovery_port,
|
||||||
@@ -963,6 +967,7 @@ impl Router {
|
|||||||
max_payload_size: self.max_payload_size,
|
max_payload_size: self.max_payload_size,
|
||||||
log_dir: self.log_dir.clone(),
|
log_dir: self.log_dir.clone(),
|
||||||
log_level: self.log_level.clone(),
|
log_level: self.log_level.clone(),
|
||||||
|
json_log: self.json_log,
|
||||||
service_discovery_config,
|
service_discovery_config,
|
||||||
prometheus_config,
|
prometheus_config,
|
||||||
request_timeout_secs: self.request_timeout_secs,
|
request_timeout_secs: self.request_timeout_secs,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class RouterArgs:
|
|||||||
api_key: Optional[str] = None
|
api_key: Optional[str] = None
|
||||||
log_dir: Optional[str] = None
|
log_dir: Optional[str] = None
|
||||||
log_level: Optional[str] = None
|
log_level: Optional[str] = None
|
||||||
|
json_log: bool = False
|
||||||
# Service discovery configuration
|
# Service discovery configuration
|
||||||
service_discovery: bool = False
|
service_discovery: bool = False
|
||||||
selector: Dict[str, str] = dataclasses.field(default_factory=dict)
|
selector: Dict[str, str] = dataclasses.field(default_factory=dict)
|
||||||
@@ -413,6 +414,11 @@ class RouterArgs:
|
|||||||
choices=["debug", "info", "warn", "error"],
|
choices=["debug", "info", "warn", "error"],
|
||||||
help="Set the logging level. If not specified, defaults to INFO.",
|
help="Set the logging level. If not specified, defaults to INFO.",
|
||||||
)
|
)
|
||||||
|
logging_group.add_argument(
|
||||||
|
f"--{prefix}json-log",
|
||||||
|
action="store_true",
|
||||||
|
help="Enable structured JSON log output instead of plain text.",
|
||||||
|
)
|
||||||
|
|
||||||
# Service discovery configuration
|
# Service discovery configuration
|
||||||
k8s_group.add_argument(
|
k8s_group.add_argument(
|
||||||
|
|||||||
@@ -260,6 +260,10 @@ struct CliArgs {
|
|||||||
#[arg(long, default_value = "info", value_parser = ["debug", "info", "warn", "error"], help_heading = "Logging")]
|
#[arg(long, default_value = "info", value_parser = ["debug", "info", "warn", "error"], help_heading = "Logging")]
|
||||||
log_level: String,
|
log_level: String,
|
||||||
|
|
||||||
|
/// Enable structured JSON log output instead of plain text
|
||||||
|
#[arg(long, default_value_t = false, help_heading = "Logging")]
|
||||||
|
json_log: bool,
|
||||||
|
|
||||||
// ==================== Prometheus Metrics ====================
|
// ==================== Prometheus Metrics ====================
|
||||||
/// Port to expose Prometheus metrics
|
/// Port to expose Prometheus metrics
|
||||||
#[arg(long, default_value_t = 29000, help_heading = "Prometheus Metrics")]
|
#[arg(long, default_value_t = 29000, help_heading = "Prometheus Metrics")]
|
||||||
@@ -1119,6 +1123,7 @@ impl CliArgs {
|
|||||||
max_payload_size: self.max_payload_size,
|
max_payload_size: self.max_payload_size,
|
||||||
log_dir: self.log_dir.clone(),
|
log_dir: self.log_dir.clone(),
|
||||||
log_level: Some(self.log_level.clone()),
|
log_level: Some(self.log_level.clone()),
|
||||||
|
json_log: self.json_log,
|
||||||
service_discovery_config,
|
service_discovery_config,
|
||||||
prometheus_config,
|
prometheus_config,
|
||||||
request_timeout_secs: self.request_timeout_secs,
|
request_timeout_secs: self.request_timeout_secs,
|
||||||
|
|||||||
@@ -533,6 +533,7 @@ pub struct ServerConfig {
|
|||||||
pub max_payload_size: usize,
|
pub max_payload_size: usize,
|
||||||
pub log_dir: Option<String>,
|
pub log_dir: Option<String>,
|
||||||
pub log_level: Option<String>,
|
pub log_level: Option<String>,
|
||||||
|
pub json_log: bool,
|
||||||
pub service_discovery_config: Option<ServiceDiscoveryConfig>,
|
pub service_discovery_config: Option<ServiceDiscoveryConfig>,
|
||||||
pub prometheus_config: Option<PrometheusConfig>,
|
pub prometheus_config: Option<PrometheusConfig>,
|
||||||
pub request_timeout_secs: u64,
|
pub request_timeout_secs: u64,
|
||||||
@@ -722,7 +723,7 @@ pub async fn startup(config: ServerConfig) -> Result<(), Box<dyn std::error::Err
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(Level::INFO),
|
.unwrap_or(Level::INFO),
|
||||||
json_format: false,
|
json_format: config.json_log,
|
||||||
log_dir: config.log_dir.clone(),
|
log_dir: config.log_dir.clone(),
|
||||||
colorize: true,
|
colorize: true,
|
||||||
log_file_name: "smg".to_string(),
|
log_file_name: "smg".to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user