Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom callback #55

Closed
richjenks opened this issue Apr 17, 2015 · 5 comments
Closed

Custom callback #55

richjenks opened this issue Apr 17, 2015 · 5 comments

Comments

@richjenks
Copy link
Contributor

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.

@onno-vos-dev
Copy link
Contributor

@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.

@richjenks
Copy link
Contributor Author

@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.

@onno-vos-dev
Copy link
Contributor

@richjenks I'll email you tonight or on the weekend. :) Email from your Git page ok?

@richjenks
Copy link
Contributor Author

@onno-vos-dev thanks and yep, email on my profile is correct, I'll keep an eye out for it :)

richjenks added a commit to richjenks/KLogger that referenced this issue Apr 18, 2015
katzgrau#55

Implementation is simple: an array holds registered callables and, when a log is
written, they are called one-by-one and passed an array of info about both the
`Loggger` object and the current log item.
@tleb
Copy link

tleb commented May 31, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants