fix(2meet-data-optimizer): log info and notice events only when debug logging is on
- TMDO_Logger::info()/notice() write to the PHP error log only with WP_DEBUG_LOG (filter tmdo_log_info); every CLI run and production request printed [WPDO][INFO] lines - debug() keeps its WP_DEBUG gate; warning() and error() are unchanged - Verify: LoggerTest (2 new), unit 700, integration 577, phpcs, stan - PR: PR-095
This commit is contained in:
@@ -48,7 +48,7 @@ class TMDO_Logger {
|
||||
/**
|
||||
* Log an INFO-level event (event-based signature, used by v2.0.0 engine code).
|
||||
*
|
||||
* Writes only to PHP error_log; does NOT touch wpdo_errors (which is reserved
|
||||
* Writes only to PHP error_log, and only when debug logging is on; does NOT touch wpdo_errors (which is reserved
|
||||
* for actual errors). Mode changes / cache flushes / audit prunes call here
|
||||
* many times per request — keeping them out of the DB error table.
|
||||
*
|
||||
@@ -57,6 +57,22 @@ class TMDO_Logger {
|
||||
* @return void
|
||||
*/
|
||||
public static function info( string $event, array $context = array() ): void {
|
||||
// Routine events: only with WP_DEBUG_LOG (filter `tmdo_log_info`), or every
|
||||
// CLI run and production request would flood the log.
|
||||
if ( ! apply_filters( 'tmdo_log_info', defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) ) {
|
||||
return;
|
||||
}
|
||||
self::write_info( $event, $context );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an INFO line to the PHP error log.
|
||||
*
|
||||
* @param string $event Event name.
|
||||
* @param array<string, mixed> $context Structured context.
|
||||
* @return void
|
||||
*/
|
||||
private static function write_info( string $event, array $context ): void {
|
||||
error_log( sprintf( '[WPDO][INFO][%s] %s', $event, $context ? wp_json_encode( $context, JSON_UNESCAPED_UNICODE ) : '' ) );
|
||||
}
|
||||
|
||||
@@ -97,7 +113,7 @@ class TMDO_Logger {
|
||||
*/
|
||||
public static function debug( string $event, array $context = array() ): void {
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||
self::info( $event, $context );
|
||||
self::write_info( $event, $context );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user