Skip to content

Commit

Permalink
feat: add pid to Logger (#2290)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani authored Feb 21, 2023
1 parent 5cb9751 commit fd3011c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion includes/class-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,22 @@ public static function log( $payload, $header = 'NEWSPACK', $type = 'info' ) {
$caller_prefix = $caller ? "[$caller]" : '';
$type_prefix = 'info' != $type ? "[$type]" : '';

error_log( '[' . $header . ']' . $caller_prefix . strtoupper( $type_prefix ) . ': ' . $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( self::get_pid() . '[' . $header . ']' . $caller_prefix . strtoupper( $type_prefix ) . ': ' . $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
}

/**
* Get the current process ID and format it to the output in a way that keeps it aligned.
*
* @return string The process ID surrounded by brackets and followed by spaces to always match at least 7 characters.
*/
private static function get_pid() {
$pid = '[' . getmypid() . ']';
$len = strlen( $pid );
while ( $len < 7 ) {
$pid .= ' ';
$len++;
}
return $pid;
}

/**
Expand Down

0 comments on commit fd3011c

Please sign in to comment.