@@ -854,12 +854,12 @@ ngx_http_apisix_error_log_handler(ngx_http_request_t *r, u_char *buf, size_t len
854854
855855 loc_conf = ngx_http_get_module_loc_conf (r , ngx_http_apisix_module );
856856 if (loc_conf -> request_id_var_index == NGX_CONF_UNSET ) {
857- return buf ;
857+ return buf ;
858858 }
859859
860860 request_id_var = ngx_http_get_indexed_variable (r , loc_conf -> request_id_var_index );
861861 if (request_id_var == NULL || request_id_var -> not_found ) {
862- return buf ;
862+ return buf ;
863863 }
864864 buf = ngx_snprintf (buf , len , ", request_id: \"%v\"" , request_id_var );
865865 return buf ;
@@ -875,23 +875,23 @@ ngx_http_apisix_error_log_handler(ngx_http_request_t *r, u_char *buf, size_t len
875875static u_char *
876876ngx_http_apisix_combined_error_log_handler (ngx_http_request_t * r , ngx_http_request_t * sr , u_char * buf , size_t len )
877877{
878- u_char * p ;
879- ngx_http_apisix_ctx_t * ctx ;
878+ u_char * p ;
879+ ngx_http_apisix_ctx_t * ctx ;
880880
881- ctx = ngx_http_apisix_get_module_ctx (r );
882- if (ctx == NULL || ctx -> orig_log_handler == NULL ) {
883- return buf ;
884- }
881+ ctx = ngx_http_apisix_get_module_ctx (r );
882+ if (ctx == NULL || ctx -> orig_log_handler == NULL ) {
883+ return buf ;
884+ }
885885
886- //Get the original log message
887- p = ctx -> orig_log_handler (r , sr , buf , len );
888- //p - buf calculates the number of bytes written by the original log handler into the buffer.
889- //len -= (p - buf) reduces the remaining buffer length by the amount already used.
890- len -= p - buf ;
886+ //Get the original log message
887+ p = ctx -> orig_log_handler (r , sr , buf , len );
888+ //p - buf calculates the number of bytes written by the original log handler into the buffer.
889+ //len -= (p - buf) reduces the remaining buffer length by the amount already used.
890+ len -= p - buf ;
891891
892- //Apisix log handler
893- buf = ngx_http_apisix_error_log_handler (r , buf , len );
894- return buf ;
892+ //Apisix log handler
893+ buf = ngx_http_apisix_error_log_handler (r , buf , len );
894+ return buf ;
895895}
896896
897897
@@ -900,47 +900,47 @@ ngx_http_apisix_combined_error_log_handler(ngx_http_request_t *r, ngx_http_reque
900900static ngx_int_t
901901ngx_http_apisix_replace_error_log_handler (ngx_http_request_t * r )
902902{
903- ngx_http_apisix_ctx_t * ctx ;
903+ ngx_http_apisix_ctx_t * ctx ;
904904
905- ctx = ngx_http_apisix_get_module_ctx (r );
906- if (ctx == NULL ) {
907- return NGX_OK ;
908- }
905+ ctx = ngx_http_apisix_get_module_ctx (r );
906+ if (ctx == NULL ) {
907+ return NGX_OK ;
908+ }
909909
910- if (r -> log_handler == NULL ){
911- return NGX_DECLINED ;
912- }
910+ if (r -> log_handler == NULL ){
911+ return NGX_DECLINED ;
912+ }
913913
914- /*
915- * Store the original log handler in ctx->orig_log_handler, replace
916- * it with the combined log handler, which will execute the original
917- * handler's logic in addition to our own.
918- */
919- ctx -> orig_log_handler = r -> log_handler ;
920- r -> log_handler = ngx_http_apisix_combined_error_log_handler ;
914+ /*
915+ * Store the original log handler in ctx->orig_log_handler, replace
916+ * it with the combined log handler, which will execute the original
917+ * handler's logic in addition to our own.
918+ */
919+ ctx -> orig_log_handler = r -> log_handler ;
920+ r -> log_handler = ngx_http_apisix_combined_error_log_handler ;
921921
922- return NGX_DECLINED ;
922+ return NGX_DECLINED ;
923923}
924924
925925//This function is part of postconfiguration passed to module context and will override the post_read_phase with custom log handler.
926926// It extracts the pointer to log handler from the post read phase handlers and then override that with new function address.
927927char *
928928ngx_http_apisix_error_log_init (ngx_conf_t * cf )
929929{
930- ngx_http_handler_pt * h ;
931- ngx_http_core_main_conf_t * cmcf ;
930+ ngx_http_handler_pt * h ;
931+ ngx_http_core_main_conf_t * cmcf ;
932932
933- cmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_core_module );
934- h = ngx_array_push (& cmcf -> phases [NGX_HTTP_POST_READ_PHASE ].handlers );
935- if (h == NULL ) {
936- ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
937- "failed setting error log handler" );
938- return NGX_CONF_ERROR ;
939- }
933+ cmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_core_module );
934+ h = ngx_array_push (& cmcf -> phases [NGX_HTTP_POST_READ_PHASE ].handlers );
935+ if (h == NULL ) {
936+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
937+ "failed setting error log handler" );
938+ return NGX_CONF_ERROR ;
939+ }
940940
941- * h = ngx_http_apisix_replace_error_log_handler ;
941+ * h = ngx_http_apisix_replace_error_log_handler ;
942942
943- return NGX_CONF_OK ;
943+ return NGX_CONF_OK ;
944944}
945945
946946// This function does the translation of the configuration file to the internal representation.
@@ -949,22 +949,22 @@ char *
949949ngx_http_apisix_error_log_request_id (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
950950{
951951 ngx_str_t * value ;
952- ngx_http_apisix_loc_conf_t * loc_conf = conf ;
952+ ngx_http_apisix_loc_conf_t * loc_conf = conf ;
953953
954- value = cf -> args -> elts ;
955- if (value [1 ].data [0 ] != '$' ) {
956- ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "invalid variable name \"%V\"" , & value [1 ]);
957- return NGX_CONF_ERROR ;
958- }
954+ value = cf -> args -> elts ;
955+ if (value [1 ].data [0 ] != '$' ) {
956+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "invalid variable name \"%V\"" , & value [1 ]);
957+ return NGX_CONF_ERROR ;
958+ }
959959
960- value [1 ].len -- ;
961- value [1 ].data ++ ;
960+ value [1 ].len -- ;
961+ value [1 ].data ++ ;
962962
963- loc_conf -> request_id_var_index = ngx_http_get_variable_index (cf , & value [1 ]);
964- if (loc_conf -> request_id_var_index == NGX_ERROR ) {
965- return NGX_CONF_ERROR ;
966- }
963+ loc_conf -> request_id_var_index = ngx_http_get_variable_index (cf , & value [1 ]);
964+ if (loc_conf -> request_id_var_index == NGX_ERROR ) {
965+ return NGX_CONF_ERROR ;
966+ }
967967
968- return NGX_CONF_OK ;
968+ return NGX_CONF_OK ;
969969}
970970
0 commit comments