betterlog 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/betterlog.gemspec +2 -2
- data/lib/betterlog/log.rb +5 -2
- data/lib/betterlog/version.rb +1 -1
- data/spec/betterlog/log_spec.rb +9 -2
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 881c76f1faf7c6783210c43f1c4c720d43cfc794da8385c27267080325f01af2
         | 
| 4 | 
            +
              data.tar.gz: 6e266178a87eb7c1f526bcb9a70fc13b5bfc5ff642d8b2a63b0bb95e4b43053b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3036a50353157aece676091b0f245cbe30976fd707a214863546768bf3a20aa736c016c0e730f7cca11817fb410e293a40f20e2999620e6350b183d531e6d069
         | 
| 7 | 
            +
              data.tar.gz: 4abee0552ed87ff53b35f562d5306c8edd24b18e45f4deed25e2b33098b9dea0d57e911f0a4b3914187c94f483557a163d3833ce1e386f1a63fc043b0dc53054
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.12.0
         | 
    
        data/betterlog.gemspec
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            -
            # stub: betterlog 0. | 
| 2 | 
            +
            # stub: betterlog 0.12.0 ruby lib
         | 
| 3 3 |  | 
| 4 4 | 
             
            Gem::Specification.new do |s|
         | 
| 5 5 | 
             
              s.name = "betterlog".freeze
         | 
| 6 | 
            -
              s.version = "0. | 
| 6 | 
            +
              s.version = "0.12.0"
         | 
| 7 7 |  | 
| 8 8 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
         | 
| 9 9 | 
             
              s.require_paths = ["lib".freeze]
         | 
    
        data/lib/betterlog/log.rb
    CHANGED
    
    | @@ -90,10 +90,12 @@ module Betterlog | |
| 90 90 | 
             
                #
         | 
| 91 91 | 
             
                # @param name the name of the recorded metric.
         | 
| 92 92 | 
             
                # @param value of the recorded metric, defaults to duration if block was given.
         | 
| 93 | 
            +
                # @param success a Proc with parameter +result+ that returns true iff block
         | 
| 94 | 
            +
                #        result was asuccessful
         | 
| 93 95 | 
             
                # @param **rest additional rest is logged as well.
         | 
| 94 96 | 
             
                # @return [ Log ] this object itself.
         | 
| 95 | 
            -
                def metric(name:, value: nil, **rest, &block)
         | 
| 96 | 
            -
                  time_block(&block)
         | 
| 97 | 
            +
                def metric(name:, value: nil, success: -> result { true }, **rest, &block)
         | 
| 98 | 
            +
                  result = time_block(&block)
         | 
| 97 99 | 
             
                rescue => error
         | 
| 98 100 | 
             
                  e = Log::Event.ify(error)
         | 
| 99 101 | 
             
                  rest |= e.as_hash.subhash(:error_class, :backtrace, :message)
         | 
| @@ -107,6 +109,7 @@ module Betterlog | |
| 107 109 | 
             
                    event = build_metric(
         | 
| 108 110 | 
             
                      name:     name,
         | 
| 109 111 | 
             
                      value:    value || timed_duration,
         | 
| 112 | 
            +
                      success: success.(result),
         | 
| 110 113 | 
             
                      **rest
         | 
| 111 114 | 
             
                    )
         | 
| 112 115 | 
             
                    emit event
         | 
    
        data/lib/betterlog/version.rb
    CHANGED
    
    
    
        data/spec/betterlog/log_spec.rb
    CHANGED
    
    | @@ -147,6 +147,7 @@ describe Betterlog::Log do | |
| 147 147 | 
             
                    message:  'a metric controller.action=0.123',
         | 
| 148 148 | 
             
                    name:     'controller.action',
         | 
| 149 149 | 
             
                    value:    0.123,
         | 
| 150 | 
            +
                    success:  true,
         | 
| 150 151 | 
             
                    type:     'metric',
         | 
| 151 152 | 
             
                    severity: 'info'
         | 
| 152 153 | 
             
                  )
         | 
| @@ -159,6 +160,7 @@ describe Betterlog::Log do | |
| 159 160 | 
             
                    message:  'a metric controller.action=0.123',
         | 
| 160 161 | 
             
                    name:     'controller.action',
         | 
| 161 162 | 
             
                    value:    0.123,
         | 
| 163 | 
            +
                    success:  true,
         | 
| 162 164 | 
             
                    type:     'metric',
         | 
| 163 165 | 
             
                    severity: :info,
         | 
| 164 166 | 
             
                  )
         | 
| @@ -172,6 +174,7 @@ describe Betterlog::Log do | |
| 172 174 | 
             
                    foo:      'bar',
         | 
| 173 175 | 
             
                    name:     'controller.action',
         | 
| 174 176 | 
             
                    value:    0.123,
         | 
| 177 | 
            +
                    success:  true,
         | 
| 175 178 | 
             
                    type:     'metric',
         | 
| 176 179 | 
             
                    severity: 'info'
         | 
| 177 180 | 
             
                  )
         | 
| @@ -184,14 +187,16 @@ describe Betterlog::Log do | |
| 184 187 | 
             
                    message:   'a metric foo=10.0',
         | 
| 185 188 | 
             
                    name:      'foo',
         | 
| 186 189 | 
             
                    value:     10.0,
         | 
| 190 | 
            +
                    success:   true,
         | 
| 187 191 | 
             
                    duration:  10.0,
         | 
| 188 192 | 
             
                    timestamp: "2011-11-11T10:11:21.000Z",
         | 
| 189 193 | 
             
                    type:      'metric',
         | 
| 190 194 | 
             
                    severity:  'info'
         | 
| 191 195 | 
             
                  )
         | 
| 192 196 | 
             
                  expect(instance).to receive(:emit).with(expected_event)
         | 
| 193 | 
            -
                  Log.metric(name: 'foo') do
         | 
| 197 | 
            +
                  Log.metric(name: 'foo', success: -> result { result == :success }) do
         | 
| 194 198 | 
             
                    Time.dummy = Time.now + 10
         | 
| 199 | 
            +
                    :success
         | 
| 195 200 | 
             
                  end
         | 
| 196 201 | 
             
                end
         | 
| 197 202 |  | 
| @@ -205,6 +210,7 @@ describe Betterlog::Log do | |
| 205 210 | 
             
                  expected_event = Log::Event.new(
         | 
| 206 211 | 
             
                    name:       'foo',
         | 
| 207 212 | 
             
                    value:       3.0,
         | 
| 213 | 
            +
                    success:     false,
         | 
| 208 214 | 
             
                    duration:    3.0,
         | 
| 209 215 | 
             
                    timestamp:   "2011-11-11T10:11:14.000Z",
         | 
| 210 216 | 
             
                    message:     '"MyEx: we were fucked" while measuring metric foo',
         | 
| @@ -216,10 +222,11 @@ describe Betterlog::Log do | |
| 216 222 | 
             
                  expect(instance).to receive(:emit).with(expected_event)
         | 
| 217 223 | 
             
                  raised = false
         | 
| 218 224 | 
             
                  begin
         | 
| 219 | 
            -
                    Log.metric(name: 'foo') do
         | 
| 225 | 
            +
                    Log.metric(name: 'foo', success: -> result { result == :success }) do
         | 
| 220 226 | 
             
                      Time.dummy = Time.now + 3
         | 
| 221 227 | 
             
                      raise MyEx, "we were fucked"
         | 
| 222 228 | 
             
                      Time.dummy = Time.now + 7
         | 
| 229 | 
            +
                      :success
         | 
| 223 230 | 
             
                    end
         | 
| 224 231 | 
             
                  rescue MyEx
         | 
| 225 232 | 
             
                    raised = true
         |