Skip to content

Commit d503016

Browse files
committed
Flush log buffers every 10 minutes
1 parent cb69348 commit d503016

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bot.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ function loadEnv(string $filePath = __DIR__ . '/.env'): void
6161

6262
file_put_contents('output.log', ''); // Clear the contents of 'output.log'
6363
$fileHandler = (new StreamHandler('output.log', Level::Debug))->setFormatter(new LineFormatter(null, null, true, true, true));
64-
//$stdoutHandler = (new StreamHandler('php://stdout', Level::Info))->setFormatter(new LineFormatter(null, null, true, true, true));
65-
$logger = new Logger('Civ13', [$fileHandler, /*$stdoutHandler*/]);
64+
$stdoutHandler = (new StreamHandler('php://stdout', Level::Info))->setFormatter(new LineFormatter(null, null, true, true, true));
65+
$logger = new Logger('Civ13', [$fileHandler, $stdoutHandler]);
66+
Loop::addPeriodicTimer(60 * 10, fn() => $logger->reset()); // Flush all buffers every 10 minutes
6667
$logger->info('Loading configurations for the bot...');
6768
set_rejection_handler(function(\Throwable $e) use ($logger) {
6869
if ($e->getMessage() !== 'Cannot resume a fiber that is not suspended') $logger->warning("Unhandled Promise Rejection: {$e->getMessage()} [{$e->getFile()}:{$e->getLine()}] " . str_replace('#', '\n#', $e->getTraceAsString()));

0 commit comments

Comments
 (0)