-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02fe336
commit 79027e2
Showing
12 changed files
with
208 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/root/app/www/public/logs/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 111923 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
require 'shared.php'; | ||
|
||
if ($_POST['m'] == 'init') { | ||
$logFiles = []; | ||
$logDir = ABSOLUTE_PATH . LOGS_PATH; | ||
$dir = opendir($logDir); | ||
while ($log = readdir($dir)) { | ||
if ($log[0] != '.' && !is_dir($log)) { | ||
$logFiles[] = ['name' => $log, 'size' => filesize($logDir . $log)]; | ||
} | ||
} | ||
closedir($dir); | ||
|
||
if (!$logFiles) { | ||
echo 'No log files have been generated yet.'; | ||
} else { | ||
?> | ||
<div class="container-fluid pt-4 px-4"> | ||
<div class="bg-secondary rounded h-100 p-4"> | ||
<div class="row"> | ||
<div class="col-sm-3"> | ||
<ul> | ||
<?php | ||
foreach ($logFiles as $log) { | ||
$logHash = md5($log['name']); | ||
?> | ||
<li id="logList-<?= $logHash ?>" onclick="viewLog('<?= $log['name'] ?>', '<?= $logHash ?>')" style="cursor: pointer;" class="text-info"><?= $log['name'] ?> (<?= byteConversion($log['size']) ?>)</li> | ||
<?php } ?> | ||
</ul> | ||
</div> | ||
<div class="col-sm-9"><span id="logHeader"></span><pre id="logViewer" style="max-height: 500px; overflow: auto;"></pre></div> | ||
</div> | ||
</div> | ||
</div> | ||
<?php | ||
} | ||
} | ||
|
||
if ($_POST['m'] == 'viewLog') { | ||
$log = file(ABSOLUTE_PATH . LOGS_PATH . $_POST['name']); | ||
$header = 'Lines: ' . count($log); | ||
|
||
foreach ($log as $index => $line) { | ||
$content .= str_pad(($index + 1), strlen(count($log)), ' ', STR_PAD_RIGHT) .' | '. $line; | ||
} | ||
|
||
echo json_encode(['header' => $header, 'log' => $content]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 111923 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
define('ABSOLUTE_PATH', str_replace('crons', '', __DIR__)); | ||
require ABSOLUTE_PATH . 'loader.php'; | ||
|
||
$logfile = ABSOLUTE_PATH . LOGS_PATH . 'cron-housekeeper-' . date('Ymd') . '.log'; | ||
logger($logfile, 'Cron run started'); | ||
echo 'Cron run started: housekeeper' . "\n"; | ||
|
||
//-- LOG FILE CLEANUP (DAILY @ MIDNIGHT) | ||
logger($logfile, 'Checking time: Log file cleanup (daily @ midnight)'); | ||
if (date('H') == 0) { | ||
$logDir = ABSOLUTE_PATH . LOGS_PATH; | ||
$dir = opendir($logDir); | ||
while ($log = readdir($dir)) { | ||
if ($log[0] != '.' && !is_dir($log)) { | ||
if (date('Ymd', filemtime($logDir . $log)) != date('Ymd')) { | ||
logger($logfile, 'Removing logfile: ' . $logDir . $log); | ||
unlink($logDir . $log); | ||
} | ||
} | ||
} | ||
closedir($dir); | ||
} | ||
|
||
logger($logfile, 'Cron run finished'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 111823 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
function logger($logfile, $msg, $type = 'info') | ||
{ | ||
if (!$logfile) { | ||
return; | ||
} | ||
|
||
$backtrace = debug_backtrace(); | ||
$line = $backtrace[0]['line']; | ||
$file = $backtrace[0]['file']; | ||
$fileParts = explode('/', $file); | ||
$fileName = $fileParts[count($fileParts) - 1]; | ||
$fileFolder = $fileParts[count($fileParts) - 2]; | ||
$file = $fileFolder . '/' . $fileName; | ||
$log = date('g:i:s') . ' ' . ($type ? '[' . strtoupper($type) . '] ' : '') . $file . ' LN: ' . $line . ' :: ' . (is_array($msg) || is_object($msg) ? loggerLoopArray($msg, 0) : $msg) . "\n"; | ||
|
||
file_put_contents($logfile, $log, FILE_APPEND); | ||
} | ||
|
||
function loggerLoopArray($stack, $depth = 0, $output = '') | ||
{ | ||
$tabs = ''; | ||
|
||
for ($x = 0; $x < $depth; $x++) { | ||
$tabs .= "\t"; | ||
} | ||
|
||
if (!is_array($stack)) { | ||
$output .= $tabs . $stack; | ||
return $output; | ||
} | ||
|
||
foreach ($stack as $key => $val) { | ||
if (is_object($val)) { | ||
$val = (array) $val; | ||
} | ||
|
||
if (is_array($val)) { | ||
$output .= $tabs . '[' . $key . ']' . "\n"; | ||
$output = loggerLoopArray($val, ($depth += 1), $output); | ||
$depth -= 1; | ||
} else { | ||
$output .= $tabs . '[' . $key . '] => ' . $val . "\n"; | ||
} | ||
} | ||
|
||
return $output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function viewLog(name, hash) | ||
{ | ||
loadingStart(); | ||
|
||
$('[id^=logList-]').removeClass('*').addClass('text-info'); | ||
$('#logList-' + hash).removeClass('text-info').addClass('text-success'); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: '../ajax/logs.php', | ||
data: '&m=viewLog&name=' + name, | ||
dataType: 'json', | ||
success: function (resultData) { | ||
$('#logHeader').html(resultData.header); | ||
$('#logViewer').html(resultData.log); | ||
loadingStop(); | ||
} | ||
}); | ||
|
||
} | ||
// --------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*/5 * * * * /usr/bin/php /config/www/crons/state.php | ||
*/60 * * * * /usr/bin/php /config/www/crons/pulls.php | ||
# min hour day month weekday command | ||
*/5 * * * * /usr/bin/php /app/www/crons/state.php | ||
*/10 * * * * /usr/bin/php /app/www/crons/housekeeper.php | ||
*/60 * * * * /usr/bin/php /app/www/crons/pulls.php |