diff --git a/inc/handler/class-post-handler.php b/inc/handler/class-post-handler.php index 5033fb5f..74f8507a 100644 --- a/inc/handler/class-post-handler.php +++ b/inc/handler/class-post-handler.php @@ -121,9 +121,26 @@ public function clear() { * @param array $record Log Record. */ protected function write( array $record ): void { + $user = wp_get_current_user(); + // Capture the stack trace. $record['extra']['backtrace'] = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace + if ( $user ) { + $record['extra']['user'] = [ + 'ID' => $user->ID, + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + ]; + } + + /** + * Filter the log record. + * + * @param array $record Log record. + */ + $record = (array) apply_filters( 'ai_logger_log_record', $record ); + $transient_key = 'ai_log_' . md5( $record['message'] . $record['channel'] ); $this->queue[ $transient_key ] = $record; diff --git a/template-parts/log-display.php b/template-parts/log-display.php index eee4a30c..c740cd7a 100644 --- a/template-parts/log-display.php +++ b/template-parts/log-display.php @@ -29,7 +29,7 @@ function ai_logger_render_table( array $data ) { %s @ %s (%s)', + '%s in %s at line %s', esc_html( $item['file'] ?? 'n/a' ), esc_html( $function ), esc_html( $item['line'] ?? '?' ) @@ -38,6 +38,10 @@ function ai_logger_render_table( array $data ) { + + + +