| 4273 | } |
| 4274 | |
| 4275 | async fn write_log(Json(req): Json<WriteLogRequest>) -> Result<Json<bool>> { |
| 4276 | let extra_str = req |
| 4277 | .extra |
| 4278 | .as_ref() |
| 4279 | .map(|e| serde_json::to_string(e).unwrap_or_default()) |
| 4280 | .unwrap_or_default(); |
| 4281 | |
| 4282 | match req.level.as_str() { |
| 4283 | "debug" => tracing::debug!(service = %req.service, extra = %extra_str, "{}", req.message), |
| 4284 | "info" => tracing::info!(service = %req.service, extra = %extra_str, "{}", req.message), |
| 4285 | "warn" => tracing::warn!(service = %req.service, extra = %extra_str, "{}", req.message), |
| 4286 | "error" => tracing::error!(service = %req.service, extra = %extra_str, "{}", req.message), |
| 4287 | other => { |
| 4288 | return Err(ApiError::BadRequest(format!( |
| 4289 | "invalid log level: '{}', expected one of: debug, info, warn, error", |
| 4290 | other |
| 4291 | ))); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | Ok(Json(true)) |
| 4296 | } |
| 4297 | |
| 4298 | async fn event_stream( |
| 4299 | State(state): State<Arc<ServerState>>, |