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

Logging hooks #32

@shyam-habarakada

Description

@shyam-habarakada

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions