hatchet 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Hatchet
2
+
3
+ Ruby logging library that provides the ability to add class/module specific
4
+ filters.
5
+
6
+ This README provides a brief overview of Hatchet, [see the main site for more complete documentation and tutorials](http://gshutler.github.com/hatchet/).
7
+
8
+ [![Build Status](https://secure.travis-ci.org/gshutler/hatchet.png?branch=master)](http://travis-ci.org/gshutler/hatchet)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'hatchet'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```
27
+ $ gem install hatchet
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Logging
33
+
34
+ To use the logger you must add it to your classes as a mixin or use it to extend
35
+ your modules. Then you can call the logger through the methods `log` and
36
+ `logger`. They are aliases for the same method to ease migration.
37
+
38
+ #### Classes
39
+
40
+ ```ruby
41
+ class Foo
42
+ include Hatchet
43
+
44
+ def self.class_work
45
+ log.info { 'Doing some class work' }
46
+ end
47
+
48
+ def work
49
+ log.info { 'Doing some work' }
50
+ end
51
+
52
+ def dangerous_work
53
+ log.info { 'Attempting dangerous work' }
54
+ attempt_dangerous_work
55
+ log.info { 'Dangerous work complete' }
56
+ true
57
+ rescue => e
58
+ log.error "Dangerous work failed - #{e.message}", e
59
+ false
60
+ end
61
+ end
62
+ ```
63
+
64
+ #### Modules
65
+
66
+ ```ruby
67
+ module Bar
68
+ include Hatchet
69
+
70
+ def self.work
71
+ log.info { 'Doing some module work' }
72
+ end
73
+
74
+ def work
75
+ log.info { 'Doing some mixin work' }
76
+ end
77
+ end
78
+ ```
79
+
80
+ ### Configuration
81
+
82
+ #### Standard
83
+
84
+ ```ruby
85
+ Hatchet.configure do |config|
86
+ # Set the level to use unless overridden (defaults to :info)
87
+ config.level :info
88
+ # Set the level for a specific class/module and its children
89
+ config.level :debug, 'Namespace::Something::Nested'
90
+
91
+ # Add as many appenders as you like
92
+ config.appenders << Hatchet::LoggerAppender.new do |appender|
93
+ # Set the logger that this is wrapping (required)
94
+ appender.logger = Logger.new('log/test.log')
95
+ end
96
+ end
97
+ ```
98
+
99
+ #### Sinatra
100
+
101
+ Use the standard configuration method but also register Hatchet as a helper
102
+ where appropriate:
103
+
104
+ ```ruby
105
+ register Hatchet
106
+ ```
107
+
108
+ Note that you may have to use the `log` alias as Sinatra already has a `logger`
109
+ method.
110
+
111
+ #### Rails
112
+
113
+ Hatchet includes a Railtie that is loaded automatically and wraps the
114
+ `Rails.logger`. The Hatchet configuration object is available through
115
+ `config.hatchet` within your standard configuration files for fine-tuning your
116
+ Hatchet configuration.
117
+
118
+ To make it so your log calls are scoped to your controllers you also need to add
119
+ Hatchet to your `ApplicationController`:
120
+
121
+ ```ruby
122
+ class ApplicationController < ActionController::Base
123
+ include Hatchet
124
+ end
125
+ ```
126
+
127
+ You could include it in your models so that each of those has its own logging
128
+ context too.
129
+
130
+ ## Contributing
131
+
132
+ 1. Fork it
133
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
134
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
135
+ 4. Push to the branch (`git push origin my-new-feature`)
136
+ 5. Create new Pull Request
137
+
138
+ All pull requests should come complete with tests when appropriate and should
139
+ follow the existing style which is best described in
140
+ [Github's Ruby style guide](https://github.com/styleguide/ruby/).
141
+
data/RELEASE.md ADDED
@@ -0,0 +1,16 @@
1
+ # Release notes
2
+
3
+ ## 0.0.18
4
+
5
+ * Made the presence of a `formatter=` method on appenders optional
6
+
7
+ ## 0.0.17
8
+
9
+ * Added the ability to pass an error along with your message
10
+
11
+ ### Bug fixes
12
+
13
+ * Fixed the fallback logging if an appender raises an error whilst trying to
14
+ log a message
15
+ * Ensured all logging calls truly do return `nil` rather than it just being
16
+ part of the documented contract
@@ -58,9 +58,9 @@ module Hatchet
58
58
  # used to setup Hatchet.
59
59
  #
60
60
  # Once the block returns each of the configured appenders has its formatter
61
- # set to the default formatter if one is not already set, and its levels
62
- # Hash is set to the shared levels Hash if an explicit one has not been
63
- # provided.
61
+ # set to the default formatter if they have one and one is not already set,
62
+ # and its levels Hash is set to the shared levels Hash if an explicit one
63
+ # has not been provided.
64
64
  #
65
65
  # Example
66
66
  #
@@ -85,8 +85,8 @@ module Hatchet
85
85
  # Ensure every appender has a formatter and a level configuration.
86
86
  #
87
87
  appenders.each do |appender|
88
- appender.formatter ||= @formatter
89
- appender.levels = @levels if appender.levels.empty?
88
+ appender.formatter ||= @formatter if appender.respond_to? 'formatter='
89
+ appender.levels = @levels if appender.levels.empty?
90
90
  end
91
91
  end
92
92
 
@@ -20,8 +20,17 @@ module Hatchet
20
20
  #
21
21
  # Examples
22
22
  #
23
- # logger.info "Informational message"
24
- # logger.info { "Informational message #{potentially_expensive}" }
23
+ # log.info "Informational message"
24
+ # log.info { "Informational message #{potentially_expensive}" }
25
+ #
26
+ # It is also possible to pass an error to associate with a message. It is down
27
+ # to the appender what it will do with the error (such as including the stack
28
+ # trace) so it is recommended you still include basic information within the
29
+ # message you pass.
30
+ #
31
+ # Examples
32
+ #
33
+ # log.error "Something bad happened - #{error.message}", error
25
34
  #
26
35
  # Log messages are sent to each appender where they will be filtered and
27
36
  # invoked as configured.
@@ -4,6 +4,6 @@ module Hatchet
4
4
 
5
5
  # Public: The version of Hatchet.
6
6
  #
7
- VERSION = '0.0.17'
7
+ VERSION = '0.0.18'
8
8
 
9
9
  end
@@ -12,11 +12,17 @@ describe 'configuration' do
12
12
  describe 'appender defaults' do
13
13
  let(:set_levels) { { unique: :fake_level } }
14
14
  let(:appender) { StoringAppender.new }
15
+ let(:unformatted_appender) do
16
+ obj = Object.new
17
+ obj.extend Hatchet::LevelManager
18
+ obj
19
+ end
15
20
 
16
21
  before do
17
22
  Hatchet.configure do |config|
18
23
  config.levels = set_levels
19
24
  config.appenders << appender
25
+ config.appenders << unformatted_appender
20
26
  end
21
27
  end
22
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatchet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -47,7 +47,9 @@ files:
47
47
  - spec/spec_helper.rb
48
48
  - spec/standard_formatter_spec.rb
49
49
  - LICENSE
50
- homepage: https://github.com/gshutler/hatchet
50
+ - README.md
51
+ - RELEASE.md
52
+ homepage: http://gshutler.github.com/hatchet/
51
53
  licenses: []
52
54
  post_install_message:
53
55
  rdoc_options: []
@@ -59,18 +61,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
61
  - - ! '>='
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
- segments:
63
- - 0
64
- hash: -2041677748427944104
65
64
  required_rubygems_version: !ruby/object:Gem::Requirement
66
65
  none: false
67
66
  requirements:
68
67
  - - ! '>='
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0'
71
- segments:
72
- - 0
73
- hash: -2041677748427944104
74
70
  requirements: []
75
71
  rubyforge_project:
76
72
  rubygems_version: 1.8.17