Jump to content

Custom logger as an option


androbey
 Share

Recommended Posts

Hi, 

I don't know if this is the right place to ask this, but I hope so. 

Tracy Debugger is of course excellent and a must have for each site. 

Right now I am using the "email notification" feature, but with Tracy's "email-sent"-flag I'd have to manually check the log file, if some error ocurred in the meantime. 

I was wondering if there is any possibility to add an additional logger besides the log file, which has no "throttle", e.g. something like a Slack logger (https://tracy.nette.org/en/recipes#toc-custom-logger) (without the need to adjust the module myself). 

Hope this makes sense. 

Thanks in advance!

  • Like 1
Link to comment
Share on other sites

@androbey - I've just committed a new version which adds Slack support. It's not super well tested, but so far it's working here nicely.

You will need to edit the config settings to set the name of the slack channel and the Slack App Oauth Token of your Slack App that has permission to post to the specified channel. Not sure if you have ever set up a Slack app (bot) before, but this should get you going: https://api.slack.com/bot-users

Let me know if you have any suggestions or find any bugs.

  • Like 2
Link to comment
Share on other sites

Hi @adrian
first of all, thank you for your support and the Slack enhancement. 

I think it's a good fit, but noticed that mail support has "disappeared" (so if logging to Slack is enabled, no more mail is sent - the Slack logger replaces the mail dispatch entirely). 

It's probably nothing anybody else would use, nor that there's any real need for it (besides my imaginations): 
So here's my suggestion or better my ideas to even further improve your must-have module.

I think it would be great, if you could add a new hookable function, let's say

 

/**
* Empty hookable function. 
* Use hook before TracyDebugger:addCustomLogger to add your own logger 
*/
protected function ___addCustomLogger()
{
	//empty on purpose
}

and call this method right after you currently call the Slack logger. 

Then you would be able to add your custom logger module (for example) which takes care entirely of logging. 

Advantages of this approach: Very custom error handlers would be possible (maybe some internal monitoring tools), you could decide when to use which service (e.g. mail on exceptions, Slack message on anything else) and so on (or even use many services to spam you all at once).

I tried this approach with a quick and dirty module, which one would have to keep in mind that autoload priority has to be higher than TracyDebuggers' AND to not have TracyDebugger as a module requirement itself. 

Unfortunately I am still no expert, but it would be nice to hear your feedback on this. 

Link to comment
Share on other sites

@androbey - I've committed a new version that doesn't prevent the email and logging to Tracy log files, but it does prevent logging to Slack until the email flag is cleared.

I know this isn't ideal / complete, but it's all I have time for right now as I am finding it quite confusing to figure out how we're supposed to implement custom loggers without overriding the default ones and the logging to file is really important so I wanted to make sure that is fixed.

Hopefully I'll tackle this better in the future, including your request for a hook. Feel free to send me a PR though if you've got the time to figure this out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...