Last active
August 29, 2015 14:25
-
-
Save chongkan/1c7b9e3648960ce7ccdf to your computer and use it in GitHub Desktop.
Laravel Route for retrieving logs via browser.
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
// Authentication based on PingPong Admin package. Use your own authentication package as filter or remove this filter. ( not recommendd ) | |
Route::get('getLog', array('before' => 'admin.auth', function() { | |
$path = storage_path() . "/logs/"; | |
$date = Input::get('date'); | |
try { | |
if (!isset($date)) { | |
$latest_ctime = 0; | |
$latest_filename = ''; | |
$d = dir($path); | |
while (false !== ($entry = $d->read())) { | |
$filepath = "{$path}/{$entry}"; | |
// could do also other checks than just checking whether the entry is a file | |
if (is_file($filepath) && filectime($filepath) > $latest_ctime) { | |
$latest_ctime = filectime($filepath); | |
$latest_filename = $entry; | |
} | |
} | |
$file = file($path . $latest_filename); | |
$length = count($file) - 2000; | |
if ($length <= 0) { | |
$length = count($file); | |
} | |
echo $latest_filename . '<hr>' . PHP_EOL . PHP_EOL; | |
for ($i = count($file) - $length; $i < count($file); $i++) { | |
echo $file[$i] . '<br>' . PHP_EOL; | |
} | |
} else { | |
$filePath = $path . 'laravel-' . trim($date) . '.log'; | |
$file = file($filePath); | |
$length = count($file) - 1000; | |
if ($length <= 0) { | |
$length = count($file); | |
} | |
echo $filePath . '<hr>' . PHP_EOL . PHP_EOL; | |
for ($i = count($file) - $length; $i < count($file); $i++) { | |
echo $file[$i] . '<br>' . PHP_EOL; | |
} | |
} | |
} catch (Exception $e) { | |
echo "System Exception: " . $e->getMessage(); | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment