@@ -111,21 +111,6 @@ static const char *level_str(CBMLogLevel level) {
111111 }
112112}
113113
114- static const char * severity_str (CBMLogLevel level ) {
115- switch (level ) {
116- case CBM_LOG_DEBUG :
117- return "DEBUG" ;
118- case CBM_LOG_INFO :
119- return "INFO" ;
120- case CBM_LOG_WARN :
121- return "WARNING" ;
122- case CBM_LOG_ERROR :
123- return "ERROR" ;
124- default :
125- return "DEFAULT" ;
126- }
127- }
128-
129114static void append_char (char * buf , size_t bufsz , size_t * pos , char ch ) {
130115 if (* pos < bufsz - 1 ) {
131116 buf [* pos ] = ch ;
@@ -231,10 +216,8 @@ void cbm_log(CBMLogLevel level, const char *msg, ...) {
231216 va_start (args , msg );
232217
233218 if (g_log_format == CBM_LOG_FORMAT_JSON ) {
234- append_raw (line_buf , sizeof (line_buf ), & pos , "{\"severity\":" );
235- append_json_string (line_buf , sizeof (line_buf ), & pos , severity_str (level ));
236- append_raw (line_buf , sizeof (line_buf ), & pos , ",\"message\":" );
237- append_json_string (line_buf , sizeof (line_buf ), & pos , msg ? msg : "" );
219+ append_raw (line_buf , sizeof (line_buf ), & pos , "{\"level\":" );
220+ append_json_string (line_buf , sizeof (line_buf ), & pos , level_str (level ));
238221 append_raw (line_buf , sizeof (line_buf ), & pos , ",\"event\":" );
239222 append_json_string (line_buf , sizeof (line_buf ), & pos , msg ? msg : "" );
240223 for (;;) {
@@ -299,13 +282,13 @@ void cbm_log_mcp_request(const char *method, const char *tool_name, bool is_erro
299282 char duration_ms [CBM_SZ_32 ];
300283 snprintf (duration_ms , sizeof (duration_ms ), "%" PRId64 , duration_us / 1000 );
301284 if (tool_name && tool_name [0 ] != '\0' ) {
302- cbm_log (is_error ? CBM_LOG_WARN : CBM_LOG_INFO , "mcp.request" , "rpc.system " , "jsonrpc" ,
303- "rpc. method" , method ? method : "" , "mcp. tool.name " , tool_name , "status" ,
285+ cbm_log (is_error ? CBM_LOG_WARN : CBM_LOG_INFO , "mcp.request" , "protocol " , "jsonrpc" ,
286+ "method" , method ? method : "" , "tool" , tool_name , "status" ,
304287 is_error ? "error" : "ok" , "duration_ms" , duration_ms , NULL );
305288 } else {
306- cbm_log (is_error ? CBM_LOG_WARN : CBM_LOG_INFO , "mcp.request" , "rpc.system " , "jsonrpc" ,
307- "rpc. method" , method ? method : "" , "status" , is_error ? "error" : "ok" ,
308- "duration_ms" , duration_ms , NULL );
289+ cbm_log (is_error ? CBM_LOG_WARN : CBM_LOG_INFO , "mcp.request" , "protocol " , "jsonrpc" ,
290+ "method" , method ? method : "" , "status" , is_error ? "error" : "ok" , "duration_ms " ,
291+ duration_ms , NULL );
309292 }
310293}
311294
@@ -329,8 +312,7 @@ void cbm_log_http_request(const char *component, const char *method, const char
329312 level = CBM_LOG_WARN ;
330313 }
331314
332- cbm_log (level , "http.request" , "component" , component ? component : "" , "http.request.method" ,
333- method ? method : "" , "url.path" , safe_path , "http.response.status_code" , status_buf ,
334- "duration_ms" , duration_buf , "http.request.body.size" , request_buf ,
335- "http.response.body.size" , response_buf , NULL );
315+ cbm_log (level , "http.request" , "component" , component ? component : "" , "method" ,
316+ method ? method : "" , "path" , safe_path , "status" , status_buf , "duration_ms" ,
317+ duration_buf , "request_bytes" , request_buf , "response_bytes" , response_buf , NULL );
336318}
0 commit comments