2020-07-08 04:58:19 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This command line utility reads the optional PHP error log
|
|
|
|
* and converts the times to UTC so the events can be cross-referenced in the
|
|
|
|
* application logfile.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-07-12 06:17:40 +00:00
|
|
|
if ($argc > 2) {
|
|
|
|
$dest_tz = $argv[2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dest_tz = 'UTC';
|
|
|
|
}
|
2020-07-08 04:58:19 +00:00
|
|
|
|
|
|
|
if ($argc > 1) {
|
|
|
|
$file = $argv[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file = 'php.out';
|
|
|
|
}
|
|
|
|
|
2020-07-09 00:00:41 +00:00
|
|
|
if ($file === '-') {
|
|
|
|
$file = 'php://stdin';
|
|
|
|
}
|
|
|
|
|
2020-07-08 04:58:19 +00:00
|
|
|
$lines = @file($file);
|
|
|
|
if (! $lines) {
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lines) {
|
|
|
|
foreach ($lines as $line) {
|
2021-12-02 23:02:31 +00:00
|
|
|
if (substr($line,0,1) === '[') {
|
|
|
|
$ts = rtrim(substr($line,1,strpos($line, ']')), ']');
|
2020-07-08 04:58:19 +00:00
|
|
|
if ($ts) {
|
|
|
|
$arr = explode(' ', $ts);
|
|
|
|
if (count($arr) === 3) {
|
|
|
|
$ti = new DateTimeZone($arr[2]);
|
|
|
|
$d = new DateTime($arr[1] . ' ' . $arr[2]);
|
2021-07-12 06:17:40 +00:00
|
|
|
$to = new DateTimeZone($dest_tz);
|
2020-07-08 04:58:19 +00:00
|
|
|
$d->setTimeZone($to);
|
2021-12-02 23:02:31 +00:00
|
|
|
$o = $d->format('Y-m-d H:i:s');
|
|
|
|
echo '[' . $o . ']' . substr($line,strlen($ts) + 2);
|
2020-07-08 04:58:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|