From 932fca796fd14b37884274bcc81c235127a54e14 Mon Sep 17 00:00:00 2001 From: r4sas Date: Tue, 2 May 2023 18:16:00 +0000 Subject: [PATCH] [checker] print time to logs Signed-off-by: r4sas --- checker.php | 24 ++++++++++++------------ lib/checker.php | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/checker.php b/checker.php index ffa792c..2f9685d 100644 --- a/checker.php +++ b/checker.php @@ -21,17 +21,17 @@ if($argc == 2 && $argv[1] == "full") { $full = true; } -echo "[CHECKER] Checking lockfile" . PHP_EOL; +echo date("H:i:s") . " [CHECKER] Checking lockfile" . PHP_EOL; $fp = fopen($lockfile, 'c'); if(!flock($fp, LOCK_EX | LOCK_NB)) { - echo "[CHECKER] Looks like another checker is running, exiting..." . PHP_EOL; + echo date("H:i:s") . " [CHECKER] Looks like another checker is running, exiting..." . PHP_EOL; exit(-1); } -echo "[DB] Fetching hosts to check from database" . PHP_EOL; +echo date("H:i:s") . " [DB] Fetching hosts to check from database" . PHP_EOL; if ((($options['fullhour'] >= 0) && ($options['fullhour'] <= 23)) && date('H') == $options['fullhour'] || $full) { // check all hosts at full check hour or when argument 'full' passed - echo "[CHECKER] Starting FULL check" . PHP_EOL; + echo date("H:i:s") . " [CHECKER] Starting FULL check" . PHP_EOL; $STH = $pdo->query("SELECT `host`, `base32` FROM `hosts`"); } else { @@ -39,7 +39,7 @@ if ((($options['fullhour'] >= 0) && ($options['fullhour'] <= 23)) && date('H') = } $hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR); -echo "[BOB] Starting session for checking" . PHP_EOL; +echo date("H:i:s") . " [BOB] Starting session for checking" . PHP_EOL; $bob = new BOB($options); if ($bob->setnick()) { $bob->options(); @@ -48,11 +48,11 @@ if ($bob->setnick()) { $bob->start(); /* Sleep 10 seconds awaitng tunnels get built */ - echo "[BOB] Session started, awaiting 10 seconds for tunnels" . PHP_EOL; + echo date("H:i:s") . " [BOB] Session started, awaiting 10 seconds for tunnels" . PHP_EOL; sleep(10); } else { - echo "[BOB] Stale session is found, using it" . PHP_EOL; + echo date("H:i:s") . " [BOB] Stale session is found, using it" . PHP_EOL; $bob->getnick(); } @@ -75,17 +75,17 @@ try { }); //} catch (Amp\TimeoutException $ex) { } catch (\Throwable $ex) { - echo "[Checker] Exception: " . $ex . PHP_EOL; + echo date("H:i:s") . " [Checker] Exception: " . $ex . PHP_EOL; } -echo "[BOB] Stopping session" . PHP_EOL; +echo date("H:i:s") . " [BOB] Stopping session" . PHP_EOL; $bob->stop(); $bob->clear(); $bob = null; -echo "[DB] Saving check results" . PHP_EOL; +echo date("H:i:s") . " [DB] Saving check results" . PHP_EOL; $i = 0; $pdo->beginTransaction(); @@ -98,7 +98,7 @@ foreach ($results as $host => $ts) { $pdo->commit(); -echo "[CHECKER] Unlocking and closing lockfile" . PHP_EOL; +echo date("H:i:s") . " [CHECKER] Unlocking and closing lockfile" . PHP_EOL; fclose($fp); -echo "[CHECKER] Result: Total hosts: " . count($results) . ", Alive: " . $i . PHP_EOL; +echo date("H:i:s") . " [CHECKER] Result: Total hosts: " . count($results) . ", Alive: " . $i . PHP_EOL; diff --git a/lib/checker.php b/lib/checker.php index f7623b8..94d458d 100644 --- a/lib/checker.php +++ b/lib/checker.php @@ -44,7 +44,7 @@ class Checker implements Task { } $bob = null; - echo "Processed " . $this->base32 . ": " . ($ts ? "online" : "offline") . PHP_EOL; + echo date("H:i:s") . " Processed " . $this->base32 . ": " . ($ts ? "online" : "offline") . PHP_EOL; return $ts; } }