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

How to handle error exception message #190

Closed
derk153 opened this issue Sep 14, 2016 · 4 comments
Closed

How to handle error exception message #190

derk153 opened this issue Sep 14, 2016 · 4 comments

Comments

@derk153
Copy link

derk153 commented Sep 14, 2016

Lograge: 0.4.1
Rails: 5.0
Ruby: 2.3.1

I need to display in lograge json output error messages from exception errors

Lograge configuration:

config.logger = ActFluentLoggerRails::Logger.new
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.custom_options = lambda do |event|
  {
    params: event.payload[:params].except(%w(controller action format id)),
    tag: ENV['HOST']
  }
end

How can I add to the lograge log a message, that I'm getting in errors rescuing like this?

begin 
  yield
rescue StandardError => e
  logger.error e.message
end
@rodrigoapereira
Copy link

Same issue here.

@benlovell
Copy link
Collaborator

benlovell commented Dec 10, 2016

Don't rescue from the error and Rails will include this information in the payload with the :exception_object key. This should be trivially easy to massage into the correct shape JSON i.e. merging the backtrace into a single line.

However, it's worth stating most folks' preference is to rely on exception reporting services for this kind of stuff.

benlovell added a commit that referenced this issue Dec 10, 2016
I realised after #190 that we didn't actually document our thoughts
around exception logging. This addresses that need.
@dugsmith
Copy link

dugsmith commented Aug 1, 2017

@benlovell, I'm seeing the :exception key when an exception is thrown, but not the :exception_objectkey. Using Rails 4.2.8 with lograge 0.5.1. Is there something I need to do to enable that object, so I can add the backtrace to the JSON error log?

@dugsmith
Copy link

dugsmith commented Aug 1, 2017

@benlovell I see now, it's a Rails 5 thing.

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

4 participants