forked from peoplepath/homework-modern-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathold.php
More file actions
30 lines (26 loc) · 670 Bytes
/
old.php
File metadata and controls
30 lines (26 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$pattern = '/test\.(\w+)/';
// read and parse file
$log = file_get_contents($argv[1]);
$rows = explode(PHP_EOL, $log);
// build stats
$stats = array();
foreach ($rows as $row) {
// decorator: extract log level
if (preg_match($pattern, $row, $matches)) {
$level = strtolower($matches[1]);
// filter: do not accept DEBUG
if ($level != 'debug') {
if (array_key_exists($level, $stats)) {
$stats[$level]++;
} else {
$stats[$level] = 1;
}
}
}
}
// show stats
arsort($stats);
foreach ($stats as $level => $count) {
echo "$level: $count" . PHP_EOL;
}