Making WordPress.org


Ignore:
Timestamp:
05/31/2016 11:40:20 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Logger: Add unique request ID to log entries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/0-logger.php

    r3273 r3284  
    2929
    3030    $log_entry = sprintf(
    31         '%s:%s - %s:%s%s',
     31        '[%s] %s:%s - %s:%s%s',
     32        get_unique_request_id(),
    3233        basename( $backtrace[0]['file'] ),
    3334        $backtrace[0]['line'],
     
    6970
    7071/**
     72 * Generate a unique ID for the current request
     73 *
     74 * This is useful when debugging race conditions, etc, so that you can identify which log entries belong to each thread.
     75 *
     76 * Based on https://stackoverflow.com/a/22508709/450127
     77 *
     78 * @return string
     79 */
     80function get_unique_request_id() {
     81    return hash( 'crc32b', $_SERVER['REMOTE_ADDR'] . $_SERVER['REMOTE_PORT'] . $_SERVER['REQUEST_TIME_FLOAT'] );
     82}
     83
     84/**
    7185 * Format entries created with log()
    7286 *
     
    8195    $formatted_log        = '';
    8296    $raw_entries          = explode( "\n", $raw_log );
    83     $native_entry_pattern = '/(\[.*?\]) (.*?:.*?) - (.*?) -- (\{.*\})/';
     97    $native_entry_pattern = '/(\[.*?\]) (\[\w+\]) (.*?:.*?) - (.*?) -- (\{.*\})/';
    8498
    8599    foreach ( $raw_entries as $entry ) {
     
    88102        if ( $is_native_entry ) {
    89103            $formatted_log .= sprintf(
    90                 "\n%s %s - %s\n%s",
     104                "\n%s %s %s - %s\n%s",
    91105                $entry_parts[1],
    92106                $entry_parts[2],
    93107                $entry_parts[3],
    94                 print_r( json_decode( $entry_parts[4] ), true )
     108                $entry_parts[4],
     109                print_r( json_decode( $entry_parts[5] ), true )
    95110            );
    96111        } else {
Note: See TracChangeset for help on using the changeset viewer.