Skip to content

Commit

Permalink
Merge pull request #51 from alleyinteractive/js-user-agent
Browse files Browse the repository at this point in the history
Store the user agent on requests
  • Loading branch information
srtfisher authored Apr 8, 2022
2 parents 83f821d + b7f4e19 commit 30ac64c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions inc/class-ai-logger-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public function log() {
}

// Setup some default arguments.
$level = $args['level'] ?? 'info';
$args['context'] = $args['context'] ?? 'front-end';
$level = $args['level'] ?? 'info';

$args['context'] = $args['context'] ?? 'front-end';
$args['useragent'] = $args['useragent'] ?? sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ?? '' );

$logger = ai_logger();

Expand Down
4 changes: 3 additions & 1 deletion inc/handler/class-post-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ 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 ( empty( $log['context'] ) || 'front-end' !== $log['context'] ) {
$record['extra']['backtrace'] = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
}

if ( $user ) {
$record['extra']['user'] = [
Expand Down

0 comments on commit 30ac64c

Please sign in to comment.