Changeset 3273
- Timestamp:
- 05/30/2016 06:15:50 PM (9 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/0-logger.php
r3156 r3273 25 25 $data = (array) $data; 26 26 redact_keys( $data ); 27 $data = str_replace( "\n", '[newline]', serialize( $data ) );27 $data = str_replace( "\n", '[newline]', wp_json_encode( $data ) ); 28 28 } 29 29 … … 34 34 $backtrace[1]['function'], 35 35 $error_code, 36 $data ? ' - ' . $data : ''36 $data ? ' -- ' . $data : '' 37 37 ); 38 38 … … 67 67 return $data; 68 68 } 69 70 /** 71 * Format entries created with log() 72 * 73 * See WordCamp_CLI_Miscellaneous::format_log() for usage instructions. 74 * 75 * @param string $raw_log 76 * @param string $foreign_entries `ignore` or `include` entries that weren't created with log() 77 * 78 * @return string 79 */ 80 function format_log( $raw_log, $foreign_entries = 'include' ) { 81 $formatted_log = ''; 82 $raw_entries = explode( "\n", $raw_log ); 83 $native_entry_pattern = '/(\[.*?\]) (.*?:.*?) - (.*?) -- (\{.*\})/'; 84 85 foreach ( $raw_entries as $entry ) { 86 $is_native_entry = 1 === preg_match( $native_entry_pattern, $entry, $entry_parts ); 87 88 if ( $is_native_entry ) { 89 $formatted_log .= sprintf( 90 "\n%s %s - %s\n%s", 91 $entry_parts[1], 92 $entry_parts[2], 93 $entry_parts[3], 94 print_r( json_decode( $entry_parts[4] ), true ) 95 ); 96 } else { 97 if ( 'ignore' !== $foreign_entries ) { 98 $formatted_log .= $entry . "\n"; 99 } 100 } 101 } 102 103 return $formatted_log; 104 } -
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wp-cli-commands/miscellaneous.php
r2419 r3273 90 90 } 91 91 } 92 93 /** 94 * Print a log with our custom entries formatted for humans 95 * 96 * ## OPTIONS 97 * 98 * <raw_log> 99 * : The raw log contents, or the filename of the raw log 100 * 101 * [--foreign=<action>] 102 * : Include foreign log entries from the output, or ignore them 103 * --- 104 * default: include 105 * options: 106 * - include 107 * - ignore 108 * --- 109 * 110 * ## EXAMPLES 111 * 112 * wp wc-misc format-log /var/log/php-errors.log 113 * wp wc-misc format-log "$(grep 'foo' /var/log/php-errors.log -A 10 -B 10)" |less -S 114 * wp wc-misc format-log "$(grep 'bar' /var/log/php-errors.log)" --foreign=ignore 115 * 116 * @subcommand format-log 117 * 118 * @param array $args 119 * @param array $assoc_args 120 */ 121 public function format_log( $args, $assoc_args ) { 122 list( $raw_log ) = $args; 123 124 if ( is_file( $raw_log ) ) { 125 $raw_log = file_get_contents( $raw_log ); 126 } 127 128 $formatted_log = \WordCamp\Logger\format_log( $raw_log, $assoc_args['foreign'] ); 129 130 WP_CLI::line( "\n" . $formatted_log ); 131 } 92 132 }
Note: See TracChangeset
for help on using the changeset viewer.