Skip to content

Commit

Permalink
Adherence to the new Decalog-No-Log directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Lannoy committed Feb 18, 2021
1 parent 40b3b7c commit 02ce3eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added
- Compatibility with WordPress 5.7.
- Adherence to the new `Decalog-No-Log` directive implemented by [DecaLog 2.4.0](https://wordpress.org/plugins/decalog/).

### Changed
- Smart filter now filters `/server-status` and `/server-info` calls.
Expand Down
14 changes: 11 additions & 3 deletions includes/features/class-capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public static function pre_http_request( $preempt, $args, $url ) {
* @since 1.0.0
*/
private static function record( $response, $args, $url, $bound = 'unknown', $b_in = 0, $b_out = 0 ) {
$log_enabled = ! ( array_key_exists( 'headers', $args ) && array_key_exists( 'Decalog-No-Log', $args['headers'] ) );
try {
$host = '';
$url_parts = wp_parse_url( $url );
Expand Down Expand Up @@ -230,10 +231,14 @@ private static function record( $response, $args, $url, $bound = 'unknown', $b_i
Schema::store_statistics( $record );
$record['ts'] = $datetime->format( 'Y-m-d H:i:s' );
Memory::store_statistics( $record );
DecaLog::log( $record );
if ( $log_enabled ) {
DecaLog::log( $record );
}
}
} catch ( \Throwable $t ) {
Logger::warning( ucfirst( $bound ) . ' API record: ' . $t->getMessage(), $t->getCode() );
if ( $log_enabled ) {
Logger::warning( ucfirst( $bound ) . ' API record: ' . $t->getMessage(), $t->getCode() );
}
}
}

Expand All @@ -248,6 +253,7 @@ private static function record( $response, $args, $url, $bound = 'unknown', $b_i
* @since 1.0.0
*/
public static function http_api_debug( $response, $context, $class, $args, $url ) {
$log_enabled = ! ( array_key_exists( 'headers', $args ) && array_key_exists( 'Decalog-No-Log', $args['headers'] ) );
try {
$b_in = 0;
$b_out = 0;
Expand Down Expand Up @@ -322,7 +328,9 @@ public static function http_api_debug( $response, $context, $class, $args, $url
}
}
} catch ( \Throwable $t ) {
Logger::warning( 'Outbound API post-analysis: ' . $t->getMessage(), $t->getCode() );
if ( $log_enabled ) {
Logger::warning( 'Outbound API post-analysis: ' . $t->getMessage(), $t->getCode() );
}
}
self::record( $response, $args, $url, 'outbound', $b_in, $b_out );
}
Expand Down

0 comments on commit 02ce3eb

Please sign in to comment.