add split logs
This commit is contained in:
@@ -26,14 +26,33 @@ class LogController extends ApiController
|
||||
if($request->user()?->hasPermission('logs/' . $name)) {
|
||||
switch(strtolower($name)) {
|
||||
case 'discord':
|
||||
$contents = '';
|
||||
$outputContents = '';
|
||||
$errorContents = '';
|
||||
|
||||
// output log
|
||||
$filePath = '/home/discordbot/.pm2/logs/stemmech-discordbot-out-0.log';
|
||||
if(file_exists($filePath) === true) {
|
||||
$contents = file_get_contents($filePath);
|
||||
$outputContents = file_get_contents($filePath);
|
||||
}
|
||||
|
||||
$lines = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
return $this->respondJson(['log' => implode('', array_reverse($lines))]);
|
||||
$outputContents = implode('', array_reverse($lines));
|
||||
|
||||
// error log
|
||||
$filePath = '/home/discordbot/.pm2/logs/stemmech-discordbot-error-0.log';
|
||||
if(file_exists($filePath) === true) {
|
||||
$outputContents = file_get_contents($filePath);
|
||||
}
|
||||
|
||||
$lines = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$errorContents = implode('', array_reverse($lines));
|
||||
|
||||
return $this->respondJson([
|
||||
'log' => [
|
||||
'output' => $outputContents,
|
||||
'errors' => $errorContents,
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user