Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Logging hooks #32

Open
shyam-habarakada opened this issue Jan 16, 2018 · 0 comments
Open

Logging hooks #32

shyam-habarakada opened this issue Jan 16, 2018 · 0 comments

Comments

@shyam-habarakada
Copy link

shyam-habarakada commented Jan 16, 2018

suggestion / question

We've started using the slack-bot-server in our product and really like what it does. One improvement I wanted to make was to have it log unhandled exceptions to an error logging component or service of choice, and being able to configure that. At the moment, the only thing the server does is writing errors to the log.

To workaround, I monkey patched the log_error method like below.

module SlackBotServer::Logging
  def log_error(e, *args)
    message = "#{e} - #{e.message}"
    message += " (#{log_string(*args)})" if args.any?

    # note I changes the log levels from the defaults here as well.
    SlackBotServer.logger.error("#{message}")
    SlackBotServer.logger.debug(e.backtrace.join("\n"))

    # do custom error reporting/handling here.
    Rollbar.error(e, message)
  end
end

I went this route after looking at extending the gem sources in a way to make this less of a patch. But I didn't get to a solution that I felt good enough to submit a pull request.

Alternatives I tried were along the same line as what the gem does today in allowing you to override the SlackBotServer.logger or how you allow on_add and other hooks.

Has this been considered? Suggestions?

Based on feedback I'll be happy to work on what I started some more and submit a PR.

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

No branches or pull requests

1 participant