Author: ivan Date: Fri Nov 6 09:48:03 2015 New Revision: 1712928 URL: http://svn.apache.org/viewvc?rev=1712928&view=rev Log: Do not perform uncessary work if logging is not enabled.
* serf_private.h (serf__log_enabled): New function declaration. * logging.c (serf__log_enabled): Implement new function. * auth/auth.c (dispatch_auth): Use serf__log_enabled() find out if LOGCOMP_AUTHN logging is enabled and it worth to call serf_bucket_headers_get(). Modified: serf/trunk/auth/auth.c serf/trunk/logging.c serf/trunk/serf_private.h Modified: serf/trunk/auth/auth.c URL: http://svn.apache.org/viewvc/serf/trunk/auth/auth.c?rev=1712928&r1=1712927&r2=1712928&view=diff ============================================================================== --- serf/trunk/auth/auth.c (original) +++ serf/trunk/auth/auth.c Fri Nov 6 09:48:03 2015 @@ -232,7 +232,8 @@ static apr_status_t dispatch_auth(int co hdrs = serf_bucket_response_get_headers(response); #ifdef SERF_LOGGING_ENABLED - { + if (serf__log_enabled(LOGLVL_WARNING, LOGCOMP_AUTHN, + request->conn->config)) { const char *auth_hdr; /* ### headers_get() doesn't tell us whether to free this result Modified: serf/trunk/logging.c URL: http://svn.apache.org/viewvc/serf/trunk/logging.c?rev=1712928&r1=1712927&r2=1712928&view=diff ============================================================================== --- serf/trunk/logging.c (original) +++ serf/trunk/logging.c Fri Nov 6 09:48:03 2015 @@ -167,6 +167,36 @@ void serf__log(apr_uint32_t level, apr_u } } +int serf__log_enabled(apr_uint32_t level, apr_uint32_t comp, serf_config_t *config) +{ + log_baton_t *log_baton; + apr_status_t status; + + if (!config) { + /* If we can't get the log baton then logging is disabled for provided + level/component combination. */ + return FALSE; + } + + status = serf_config_get_object(config, SERF_CONFIG_CTX_LOGBATON, + (void **)&log_baton); + if (!status && log_baton) { + int i; + + for (i = 0; i < log_baton->output_list->nelts; i++) { + serf_log_output_t *output = APR_ARRAY_IDX(log_baton->output_list, + i, serf_log_output_t *); + if ((output->level >= level) && (comp & output->comps)) { + /* At least one log output wants to handle this level/component + combination.*/ + return TRUE; + } + } + } + + return FALSE; +} + /*** Output to system stream (stderr or stdout) or a file ***/ static apr_status_t log_to_stream_output(serf_log_output_t *output, @@ -287,4 +317,9 @@ apr_status_t serf_logging_add_output(ser return APR_SUCCESS; } +int serf__log_enabled(apr_uint32_t level, apr_uint32_t comp, serf_config_t *config) +{ + return FALSE; +} + #endif Modified: serf/trunk/serf_private.h URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1712928&r1=1712927&r2=1712928&view=diff ============================================================================== --- serf/trunk/serf_private.h (original) +++ serf/trunk/serf_private.h Fri Nov 6 09:48:03 2015 @@ -630,4 +630,10 @@ void serf__log_nopref(apr_uint32_t level void serf__log(apr_uint32_t level, apr_uint32_t comp, const char *filename, serf_config_t *config, const char *fmt, ...); +/* Returns non-zero if logging is enabled for provided LEVEL/COMP. + * This function can be useful in cases if logging information if somewhat + * expensive to obtain. */ +int serf__log_enabled(apr_uint32_t level, apr_uint32_t comp, + serf_config_t *config); + #endif