Replies: 1 comment 1 reply
-
That's a really good point @vesper8 ! 👏 I did not think about the API provided while building this tool, but I'll definitely keep it in mind for future updates. I've made a few small improvements in use Opcodes\LogViewer\Facades\LogViewer;
use Opcodes\LogViewer\Level;
$latestLogFile = LogViewer::getFiles()->latest();
$errorLogs = $latestLogFile->logs()->only(Level::Error);
$count = $errorLogs->count();
$logEntries = $errorLogs->get(); // this will load all related logs into memory. BE CAREFUL! Alternative below
// A better, less memory-intensive approach is to use the generator provided and read one log at a time
while ($log = $errorLogs->next()) {
// do something with the log returned
}
// Alternatively, you can fetch X number of logs at a time without resetting the cursor
while ($logs = $errorLogs->get(100)) {
// $logs is now a collection of 100 logs.
// The next time this gets called, it will be a collection of the NEXT 100 logs.
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm migrating from arcanedev/log-viewer because I feel like your package offers extra functionality and is more modern overall and of course very actively developed which is a big plus.
Previously, I had setup some custom commands for checking the status of logs, as well as clearing older logs.
The "log checking" command worked like this:
Check today's log file and check if the number of errors are above a certain threshold, if so, then trigger notifications/emails and include the count and summary of the errors.
I've been looking into doing the same thing using your package and I've been able to get it mostly working, but it's not exactly clean.
Here's some of what I'm currently working on:
It would be nice if there was an API that would help with some of the above tasks. I'd like to be able to do something like this:
Anyway something like this.. I think you get the idea of what I'm trying to achieve. The above code is working but it could break at any time if you make changes and it's a bit hacky.
Of course it would be even more amazing if you had a built-in "log alert" system that could be customized.
Similarly a built-in logrotate that deletes logs older than X days would also be great. It could be as simple as calling a scheduled "log cleanup" command that could be customized with "X days" as a parameter with a sensible default.
In the meantime though an API for clearing/deleting logs would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions