Changeset 2225503
- Timestamp:
- 01/10/2020 04:08:52 PM (6 years ago)
- Location:
- debug-log-list/tags/0.2.1.1
- Files:
-
- 3 edited
-
css/admin-style.css (modified) (3 diffs)
-
hybridsupply-log.php (modified) (9 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
debug-log-list/tags/0.2.1.1/css/admin-style.css
r2205111 r2225503 71 71 72 72 tr { 73 display: grid;74 grid-auto-flow: column;75 grid-template-columns: repeat(3, minmax(max-content, 1fr)) minmax(min-content, 4fr) repeat(2, minmax(max-content, 1fr));76 77 73 cursor: default; 78 74 } … … 84 80 85 81 th { 86 text-align: left; 82 text-align: left; 83 } 84 85 thead { 86 position: sticky; 87 top: 0; 88 background-color: #f4f4f4; 87 89 } 88 90 … … 91 93 } 92 94 93 tbody tr { 95 tbody tr { 94 96 95 97 } -
debug-log-list/tags/0.2.1.1/hybridsupply-log.php
r2225500 r2225503 10 10 */ 11 11 defined('HYBRIDSUPPLY_LOG_FILE') or define('HYBRIDSUPPLY_LOG_FILE', __FILE__); 12 defined('HYBRIDSUPPLY_LOG_REGEX_EXTRACT') or define('HYBRIDSUPPLY_LOG_REGEX_EXTRACT', '/\[(\d{1,2}-\w{3}-\d{4} \d{2}:\d{2}:\d{2}).*\]\w*\w*\s*([ \w]*):?\s*(.+)/');13 12 14 13 function hybridsupply_log_options_html() { … … 27 26 28 27 if ( file_exists($logfile) ) { 29 $logfile_contents = file_get_contents( $logfile ); 30 31 preg_match_all(HYBRIDSUPPLY_LOG_REGEX_EXTRACT , $logfile_contents, $output, PREG_SET_ORDER); 32 33 for ($i=0; $i < count($output); $i++) { 34 for ($ii=0; $ii < count($output[$i]); $ii++) { 35 $part = $output[$i][$ii] ? $output[$i][$ii] : 'Unknown'; 36 37 if ( substr($part, 0, 4) === '<!--' ) { 38 $part = esc_html($part); 39 } 40 41 switch ($ii) { 42 case 0: 43 $log[$i] = new stdClass(); 44 $log[$i]->fullmatch = $part; 45 break; 46 47 case 1: 48 $log[$i]->time = $part; 49 break; 50 51 case 2: 52 $log[$i]->type = $part; 53 break; 54 55 case 3: 56 $hash = hash( 'crc32', $part ); 57 58 if ( ! in_array($hash, $log_hashes) ) { 59 $log_hashes[] = $hash; 60 } 61 62 $log[$i]->folder =''; 63 $log[$i]->message = $part; 64 $log[$i]->hash = $hash; 65 $log[$i]->occurrences = 1; 66 $log[$i]->options = '<form method="post"><input type="hidden" name="action" value="delete"><input type="hidden" name="hash" value="' . $hash . '"><button type="submit" class="button button">Remove</button></form>'; 67 break; 68 } 69 } 28 /* Read file into an array */ 29 $logfile_contents = file( $logfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); 30 31 /* Extract information per line */ 32 for ($i=0; $i < count($logfile_contents); $i++) { 33 $n = count($log); 34 $log[$n] = new stdClass(); 35 36 /* Timestamp */ 37 if ( preg_match('/\d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2}/', $logfile_contents[$i], $matches) ) { 38 $log[$n]->timestamp = $matches[0]; 39 } 40 else { 41 $log[$n]->timestamp = ''; 42 } 43 44 /* Type */ 45 if ( preg_match('/\]\s*([\w ]*\w)/', $logfile_contents[$i], $matches) ) { 46 $log[$n]->type = $matches[1]; 47 } 48 else { 49 $log[$n]->type = ''; 50 } 51 52 /* Message */ 53 if ( preg_match('/\]\s*[\w ]*\w\W+(.+)/', $logfile_contents[$i], $matches) ) { 54 $log[$n]->message = substr($matches[1], 0, 4) === '<!--' ? esc_html( $matches[1] ) : $matches[1]; 55 } 56 else { 57 $log[$n]->message = ''; 58 } 59 60 /* Hash */ 61 if ( preg_match('/\]\s*[\w ]*\w\W+(.+)/', $logfile_contents[$i], $matches) ) { 62 $log[$n]->hash = hash( 'crc32' , $log[$n]->message ); 63 } 64 else { 65 $log[$n]->hash = ''; 66 } 67 68 /* Plugin */ 69 if ( preg_match('/plugins\/[^\/.]+/', $logfile_contents[$i], $matches) ) { 70 $log[$n]->plugin = $matches[0]; 71 } 72 else { 73 $log[$n]->plugin = ''; 74 } 75 76 /* Folder */ 77 if ( preg_match('/ \/[\w\/\-_\.]+/', $logfile_contents[$i], $matches) ) { 78 $log[$n]->folder = $matches[0]; 79 } 80 else { 81 $log[$n]->folder = ''; 82 } 83 84 /* File */ 85 if ( preg_match('/ \/[\w\/\-_\.]+/', $logfile_contents[$i], $matches) ) { 86 $log[$n]->file = $matches[0]; 87 } 88 else { 89 $log[$n]->file = ''; 90 } 91 92 /* Line */ 93 if ( preg_match('/on line \d+/', $logfile_contents[$i], $matches) ) { 94 $log[$n]->line = $matches[0]; 95 } 96 else { 97 $log[$n]->line = ''; 98 } 99 100 /* Occurrences */ 101 $log[$n]->occurrences = 1; 102 103 /* Options */ 104 $log[$n]->options = '<form method="post"><input type="hidden" name="action" value="delete"><input type="hidden" name="hash" value="' . $log[$n]->hash . '"><button type="submit" class="button button">Remove</button></form>'; 70 105 } 71 72 hybridsupply_log_count(array(73 'count' => count($log_hashes),74 'count_all' => count($log),75 ));76 106 77 107 /* … … 119 149 <?php 120 150 if ( $logfile_contents && file_exists($logfile) ) { 121 if ( $output) { ?>151 if ( TRUE ) { ?> 122 152 <table> 123 153 <thead> … … 125 155 <th class="time">Time</th> 126 156 <th class="type">Type</th> 157 <th class="message">Message</th> 158 <th class="plugin">Plugin</th> 127 159 <th class="folder">Folder</th> 128 <th class="message">Message</th> 160 <th class="file">File</th> 161 <th class="line">Line</th> 129 162 <th class="occurrences">Occurrences</th> 130 163 <th class="options">Options</th> … … 134 167 <tbody> 135 168 <?php 136 $log_hashes = array();137 138 169 for ($i=0; $i < count($log); $i++) { 139 170 if ( ! in_array($log[$i]->hash, $log_hashes) ) { … … 148 179 foreach ($log[$i] as $key => $value) { 149 180 switch ($key) { 150 case 'time ':181 case 'timestamp': 151 182 echo '<td>' . date(get_option('date_format') . ' ' . get_option('time_format'), strtotime( $value) ) . '</td>'; 152 break;153 154 case 'folder':155 echo '<td>' . $value . '</td>';156 183 break; 157 184 158 185 case 'message': 159 186 echo '<td class="message">' . $value . '</td>'; 187 break; 188 189 case 'plugin': 190 $folder = substr($value, 8) ? substr($value, 8) : NULL; 191 $plugin; 192 193 if ( $folder ) { 194 $files = glob(WP_PLUGIN_DIR . '/' . $folder . '/*.php'); 195 196 for ($i=0; $i < count( $files ); $i++) { 197 $plugin = get_plugin_data( $files[$i], FALSE, FALSE ); 198 199 if ( $plugin['Name'] != '' ) { 200 break; 201 } 202 } 203 204 echo '<td>' . $plugin['Name'] . '</td>'; 205 } 206 else { 207 echo '<td></td>'; 208 } 209 break; 210 211 case 'folder': 212 echo '<td>' . dirname($value) . '</td>'; 213 break; 214 215 case 'file': 216 echo '<td>' . basename($value) . '</td>'; 217 break; 218 219 case 'line': 220 echo '<td>' . substr($value, 8) . '</td>'; 160 221 break; 161 222 … … 193 254 echo '<p>Sorry about that.</p>'; 194 255 echo '<textarea>'; 195 echo $logfile_contents;256 echo var_dump($logfile_contents); 196 257 echo '</textarea>'; 197 258 } … … 338 399 * Function: Extract Log 339 400 */ 340 function hybridsupply_log_count_determine() { 401 function hybridsupply_log_count_determine() {/* 341 402 $log = array(); 342 403 $log_hashes = array(); … … 374 435 'count_all' => count($log), 375 436 )); 376 }437 */} 377 438 378 439 /* -
debug-log-list/tags/0.2.1.1/readme.txt
r2225500 r2225503 32 32 == Changelog == 33 33 34 = 0.2.1.1 = 35 36 * Rewrote code for better understanding 37 * Further updated RegEx for better Log extraction 38 * Table is no longer a css grid 39 * added Plugin, Folder, File, Line columns 40 34 41 = 0.1.1.1 = 35 42
Note: See TracChangeset
for help on using the changeset viewer.