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:
@@ -354,6 +354,7 @@ struct Router {
|
||||
api_key: Option<String>,
|
||||
log_dir: Option<String>,
|
||||
log_level: Option<String>,
|
||||
json_log: bool,
|
||||
service_discovery: bool,
|
||||
selector: HashMap<String, String>,
|
||||
service_discovery_port: u16,
|
||||
@@ -657,6 +658,7 @@ impl Router {
|
||||
api_key = None,
|
||||
log_dir = None,
|
||||
log_level = None,
|
||||
json_log = false,
|
||||
service_discovery = false,
|
||||
selector = HashMap::new(),
|
||||
service_discovery_port = 80,
|
||||
@@ -743,6 +745,7 @@ impl Router {
|
||||
api_key: Option<String>,
|
||||
log_dir: Option<String>,
|
||||
log_level: Option<String>,
|
||||
json_log: bool,
|
||||
service_discovery: bool,
|
||||
selector: HashMap<String, String>,
|
||||
service_discovery_port: u16,
|
||||
@@ -842,6 +845,7 @@ impl Router {
|
||||
api_key,
|
||||
log_dir,
|
||||
log_level,
|
||||
json_log,
|
||||
service_discovery,
|
||||
selector,
|
||||
service_discovery_port,
|
||||
@@ -963,6 +967,7 @@ impl Router {
|
||||
max_payload_size: self.max_payload_size,
|
||||
log_dir: self.log_dir.clone(),
|
||||
log_level: self.log_level.clone(),
|
||||
json_log: self.json_log,
|
||||
service_discovery_config,
|
||||
prometheus_config,
|
||||
request_timeout_secs: self.request_timeout_secs,
|
||||
|
||||
@@ -45,6 +45,7 @@ class RouterArgs:
|
||||
api_key: Optional[str] = None
|
||||
log_dir: Optional[str] = None
|
||||
log_level: Optional[str] = None
|
||||
json_log: bool = False
|
||||
# Service discovery configuration
|
||||
service_discovery: bool = False
|
||||
selector: Dict[str, str] = dataclasses.field(default_factory=dict)
|
||||
@@ -413,6 +414,11 @@ class RouterArgs:
|
||||
choices=["debug", "info", "warn", "error"],
|
||||
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
|
||||
k8s_group.add_argument(
|
||||
|
||||
@@ -260,6 +260,10 @@ struct CliArgs {
|
||||
#[arg(long, default_value = "info", value_parser = ["debug", "info", "warn", "error"], help_heading = "Logging")]
|
||||
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 ====================
|
||||
/// Port to expose 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,
|
||||
log_dir: self.log_dir.clone(),
|
||||
log_level: Some(self.log_level.clone()),
|
||||
json_log: self.json_log,
|
||||
service_discovery_config,
|
||||
prometheus_config,
|
||||
request_timeout_secs: self.request_timeout_secs,
|
||||
|
||||
@@ -533,6 +533,7 @@ pub struct ServerConfig {
|
||||
pub max_payload_size: usize,
|
||||
pub log_dir: Option<String>,
|
||||
pub log_level: Option<String>,
|
||||
pub json_log: bool,
|
||||
pub service_discovery_config: Option<ServiceDiscoveryConfig>,
|
||||
pub prometheus_config: Option<PrometheusConfig>,
|
||||
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),
|
||||
json_format: false,
|
||||
json_format: config.json_log,
|
||||
log_dir: config.log_dir.clone(),
|
||||
colorize: true,
|
||||
log_file_name: "smg".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user