asenchi / scrolls

Simple logging
MIT License
158 stars 26 forks source link

Add #single_line_exceptions feature. #51

Closed asenchi closed 10 years ago

asenchi commented 10 years ago

This adds a new feature for managing exception data in generated log messages. Default behavior is to generate a log message for each line of the backtrace, the result of which could be many lines for a single exception. To cut down on duplication and data transport this generates a single log message for the exception, joining all backtrace lines by '\n'.

Before

now="2014-01-23T13:22:32Z" app=scrolls deploy=nil at=exception class=NoMethodError message="undefined method `empty?' for nil:NilClass" exception_id=70161806013660
now="2014-01-23T13:22:32Z" app=scrolls deploy=nil at=exception class="undefined method `empty?' for nil:NilClass" exception_id=70161806013660 site="./test.rb:16:in <main>"

After

now="2014-01-23T13:22:59Z" app=scrolls deploy=nil at=exception class=NoMethodError message="undefined method `empty?' for nil:NilClass" exception_id=70116515914640
asenchi commented 10 years ago

I need to find a method for generating a longer exception, both for examples above and tests. Anyone have ideas?

jasonrudolph commented 10 years ago

I need to find a method for generating a longer exception, both for examples above and tests.

Here's one option to consider: https://gist.github.com/jasonrudolph/584058a67b64d89e9957

There might be a better way to accomplish this, but that approach would probably work for testing purposes.

You mentioned that you're also hoping to generate long exceptions for use in examples. The approach above will probably not work for that purpose. It would produce some pretty boring examples. ;-)

asenchi commented 10 years ago

Oh, nice, I'll work that up this afternoon.

asenchi commented 10 years ago

Alright, fixed this up, need to work on tests yet:

Before

now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:11:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:16:in <main>"

Scrolls.single_line_exceptions = true

now="2014-01-23T19:31:02Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70171943639240 site="./test.rb:11:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:16:in <main>"
asenchi commented 10 years ago

Alright, we've got tests. Going to ship a new version with this.