Custom callback
Closed this issue · 5 comments
Does anyone think the addition of custom callback feature would be of value? It could be passed the Logger
object and/or Logger::lastLine
and would open a lot of possibilities, for example:
- Send an email if the level is
notice
or higher - Log
emergency
issues to a separate file - Mirror logs to a database
- Delete/archive log files on a schedule
The developer would have to write the implementations themself (e.g. database connections) but custom callbacks might be a good way to allow advanced logging features without affecting how easy-to-use the basic functions are.
If people think this is of value I'll look into this feature.
@richjenks I currently have a custom layer on top of KLogger which sends out an email alarm if a critical or error level is detected. Also, it's able to parse the logfile to a database so yes I think this could be a nice feature!
Let me know if you need any help as you might be able to get some inspiration of my codebase.
@onno-vos-dev I do the same thing too and thought it would feel cleaner as a callback rather than a wrapper class. It would at least decouple the logger and custom code a bit.
Is your custom layer available online so I can have a look? I have a basic idea of how this would work but would appreciate a use-case for perspective.
@richjenks I'll email you tonight or on the weekend. :) Email from your Git page ok?
@onno-vos-dev thanks and yep, email on my profile is correct, I'll keep an eye out for it :)
Would it not be a better implementation to use filters: callbacks would have a list of rules, if each rule is met, then the callback is called? Of course, a callback could not have any rule.