grizzled-rails-logger 0.1.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.
Files changed (43) hide show
  1. data/LICENSE.md +31 -0
  2. data/README.md +190 -0
  3. data/Rakefile +118 -0
  4. data/grizzled-rails-logger.gemspec +30 -0
  5. data/lib/grizzled.rb +42 -0
  6. data/lib/grizzled/rails.rb +42 -0
  7. data/lib/grizzled/rails/logger.rb +125 -0
  8. data/rdoc/Grizzled.html +138 -0
  9. data/rdoc/Grizzled/Rails.html +138 -0
  10. data/rdoc/Grizzled/Rails/Logger.html +207 -0
  11. data/rdoc/Grizzled/Rails/Logger/Extension.html +314 -0
  12. data/rdoc/Grizzled/Rails/Logger/Railtie.html +138 -0
  13. data/rdoc/created.rid +4 -0
  14. data/rdoc/images/brick.png +0 -0
  15. data/rdoc/images/brick_link.png +0 -0
  16. data/rdoc/images/bug.png +0 -0
  17. data/rdoc/images/bullet_black.png +0 -0
  18. data/rdoc/images/bullet_toggle_minus.png +0 -0
  19. data/rdoc/images/bullet_toggle_plus.png +0 -0
  20. data/rdoc/images/date.png +0 -0
  21. data/rdoc/images/find.png +0 -0
  22. data/rdoc/images/loadingAnimation.gif +0 -0
  23. data/rdoc/images/macFFBgHack.png +0 -0
  24. data/rdoc/images/package.png +0 -0
  25. data/rdoc/images/page_green.png +0 -0
  26. data/rdoc/images/page_white_text.png +0 -0
  27. data/rdoc/images/page_white_width.png +0 -0
  28. data/rdoc/images/plugin.png +0 -0
  29. data/rdoc/images/ruby.png +0 -0
  30. data/rdoc/images/tag_green.png +0 -0
  31. data/rdoc/images/wrench.png +0 -0
  32. data/rdoc/images/wrench_orange.png +0 -0
  33. data/rdoc/images/zoom.png +0 -0
  34. data/rdoc/index.html +109 -0
  35. data/rdoc/js/darkfish.js +116 -0
  36. data/rdoc/js/jquery.js +32 -0
  37. data/rdoc/js/quicksearch.js +114 -0
  38. data/rdoc/js/thickbox-compressed.js +10 -0
  39. data/rdoc/lib/grizzled/rails/logger_rb.html +71 -0
  40. data/rdoc/lib/grizzled/rails_rb.html +102 -0
  41. data/rdoc/lib/grizzled_rb.html +102 -0
  42. data/rdoc/rdoc.css +763 -0
  43. metadata +100 -0
data/LICENSE.md ADDED
@@ -0,0 +1,31 @@
1
+ Grizzled Rails Logger is released under a **BSD license**, adapted from
2
+ <http://opensource.org/licenses/bsd-license.php>
3
+
4
+ Copyright &copy; 2012 Brian M. Clapper.
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ * Neither the names "clapper.org", "Grizzled Rails Logger", nor the names of
18
+ any contributors may be used to endorse or promote products derived from this
19
+ software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # grizzled-rails-logger
2
+
3
+ *Grizzled Rails Logger* is a Ruby gem that provides an add-on for the stock
4
+ Rails 3 logger.
5
+
6
+ The `Grizzled::Rails::Logger` module augments the Rails 3
7
+ `ActiveSupport::BufferedLogger` class, providing some additional
8
+ capabilities, including:
9
+
10
+ * Configurable colorized logging (colorized by severity).
11
+ * Simple timestamp configuration.
12
+ * The ability to include the PID in each message.
13
+ * The ability to flatten the log output, removing spurious newlines, so that
14
+ each message occupies only one line.
15
+ * An `exception` message that dumps an exception backtrace to the log
16
+
17
+ # Installation for Rails 3
18
+
19
+ Add the following to your `Gemfile`, and run `bundle install`:
20
+
21
+ gem 'grizzled-rails-logger'
22
+
23
+ If you want the development version of the gem, use:
24
+
25
+ gem 'grizzled-rails-logger', :git => 'git://github.com/bmc/grizzled-rails-logger.git'
26
+
27
+ # Configuration
28
+
29
+ Becaue *Grizzled Rails Logger* merely adds to the standard Rails logger,
30
+ you can continue to all the usual capabilities of the Rails logger (such as,
31
+ for instance, tagged logged).
32
+
33
+ To configure *Grizzled Rails Logger*, add a section like the following to your
34
+ `config/application.rb` file or your individual environment file:
35
+
36
+ Grizzled::Rails::Logger.configure do |cfg|
37
+ # Configuration data goes here
38
+ end
39
+
40
+ The default configuration is equivalent to the following:
41
+
42
+ Grizzled::Rails::Logger.configure do |cfg|
43
+ cfg.flatten = true
44
+ cfg.format = '%[T] (%S) %P %M'
45
+ cfg.timeformat = '%Y/%m/%d %H:%M:%S'
46
+ cfg.colorize = true
47
+ cfg.colors = {
48
+ :debug => Term::ANSIColor.cyan,
49
+ :warn => Term::ANSIColor.yellow + Term::ANSIColor.bold,
50
+ :fatal => Term::ANSIColor.red + Term::ANSIColor.bold,
51
+ :error => Term::ANSIColor.red
52
+ }
53
+ end
54
+
55
+ Each configuration option is described in more detail, below.
56
+
57
+ ## Colorization
58
+
59
+ By default, *Grizzled Rails Logger* colorizes logging output, using ANSI
60
+ terminal escape sequences (as defined by the [term-ansicolor][] gem).
61
+
62
+ You can disable colorization by setting the `colorize` option to `false`:
63
+
64
+ Grizzled::Rails::Logger.configure do |cfg|
65
+ cfg.colorize = false
66
+ end
67
+
68
+ You can also change the colors associated with each severity. Suppose, for
69
+ instance, that you want INFO messages (which normally aren't colorized) to be
70
+ white, and you wanted DEBUG messages (which are normally cyan) to be bold blue.
71
+ You'd simply reconfigure those values, as shown below:
72
+
73
+ Grizzled::Rails::Logger.configure do |cfg|
74
+ cfg.colors[:debug] = Term::ANSIColor.bold + Term::ANSIColor.blue
75
+ cfg.colors[:info] = Term::ANSIColor.white
76
+ end
77
+
78
+ `Term::ANSIColor` is automatically included for you.
79
+
80
+ **WARNING:** *Grizzled Rails Logger* does not verify that the values you
81
+ store in the color settings are legal ANSI sequences. The following is
82
+ perfectly legal, though probably not what you want:
83
+
84
+ Grizzled::Rails::Logger.configure do |cfg|
85
+ cfg.colors[:debug] = "red"
86
+ end
87
+
88
+ With that setting, a debug message that normally looks like this:
89
+
90
+ [2012/04/12 14:43:22] (DEBUG) 9816 My debug message
91
+
92
+ will, instead, look like this:
93
+
94
+ red[2012/04/12 14:43:22] (DEBUG) 9816 My debug message
95
+
96
+ ## Exception logging
97
+
98
+ *Grizzled Rails Logger* adds an `exception()` method, providing an easy way
99
+ to dump a rescued exception and its backtrace:
100
+
101
+ begin
102
+ # Some dangerous operation
103
+ rescue Exception => ex
104
+ logger.exception("Error while doing dangerous thing", ex)
105
+ end
106
+
107
+ The method takes three parameters, one of which is optional:
108
+
109
+ * `message` - a message to be displayed along with the exception. Can be nil,
110
+ but must be supplied.
111
+ * `exception` - the exception to be dumped.
112
+ * `progname` - program name. Optional; defaults to nil.
113
+
114
+ The exception is dumped at severity level ERROR.
115
+
116
+ Regardless of the setting of `flatten` (see below), the exception's backtrace
117
+ is always displayed on multiple lines.
118
+
119
+ ## Flattening
120
+
121
+ The default Rails logger includes lots of newlines in its log messages. For
122
+ example:
123
+
124
+ [2012/04/12 14:59:48] (INFO) 10102 [659d08c8cbcf3ddf543ca3710cee2771]
125
+
126
+ Started GET "/about" for 127.0.0.1 at 2012-04-12 14:59:48 -0400
127
+
128
+ *Grizzled Rails Logger* automatically flattens log messages to a single line:
129
+
130
+ [2012/04/12 14:59:48] (INFO) 10102 [659d08c8cbcf3ddf543ca3710cee2771] Started GET "/about" for 127.0.0.1 at 2012-04-12 14:59:48 -0400
131
+
132
+ If you prefer *not* to flatten log messages, disable the `flatten` setting:
133
+
134
+ Grizzled::Rails::Logger.configure do |cfg|
135
+ cfg.flatten = false
136
+ end
137
+
138
+ **NOTE:** Exception backtraces are *never* flattened.
139
+
140
+ ## Formatting
141
+
142
+ Two settings control formatting.
143
+
144
+ ### Message format
145
+
146
+ The `format` setting controls overall message formatting. Four escape
147
+ sequences control how the message is assembled:
148
+
149
+ * `%T` - Any "%T" sequences in the format are replaced by the current time.
150
+ The format of the time is controlled by `timeformat` (see below).
151
+ * `%P` - Any "%P" sequences are replaced with the process ID of the Rails
152
+ instance that's emitting the message.
153
+ * `%S` - Any "%S" sequences are replaced with an upper case string
154
+ representation of the message's severity (e.g., "ERROR", "WARN").
155
+ * `%M` - Any "%M" sequences are replaced by the message, including any
156
+ tags inserted via tagged logging.
157
+
158
+ Any other characters, including blanks, are emitted verbatim.
159
+
160
+ It's legal (but probably silly) to include a sequence multiple times. If you
161
+ don't want a specific value to be logged, simply omit its escape sequence
162
+ from the format.
163
+
164
+ The default format is: `[%T] (%S) %P %M`.
165
+
166
+ For example, to change the log format to omit the PID, use:
167
+
168
+ Grizzled::Rails::Logger.configure do |cfg|
169
+ cfg.format = '[%T] (%S) %M'
170
+ end
171
+
172
+
173
+ ### Time format
174
+
175
+ The `timeformat` setting controls how the current time (see "%T", above) is
176
+ formatted. `timeformat` is a [strftime][] format string.
177
+
178
+ The default time format is: `%Y/%m/%d %H:%M:%S`
179
+
180
+ # Alternatives
181
+
182
+ Alternatives to this gem include:
183
+
184
+ * Paul Dowman's [better_logging][] gem
185
+ * [itslog][]
186
+
187
+ [better_logging]: https://github.com/pauldowman/better_logging
188
+ [itslog]: https://github.com/johnnytommy/itslog
189
+ [term-ansicolor]: https://github.com/flori/term-ansicolor
190
+ [strftime]: http://strftime.net/
data/Rakefile ADDED
@@ -0,0 +1,118 @@
1
+ #
2
+ #
3
+ # NOTE: Man pages use the 'ronn' gem. http://rtomayko.github.com/ronn/
4
+
5
+ require 'rake/clean'
6
+ require 'pathname'
7
+
8
+ PACKAGE = 'grizzled-rails-logger'
9
+ GEMSPEC = "#{PACKAGE}.gemspec"
10
+ RDOC_OUT_DIR = 'rdoc'
11
+ GH_PAGES_DIR = File.join('..', 'gh-pages')
12
+ RDOC_PUBLISH_DIR = File.join(GH_PAGES_DIR, 'apidocs')
13
+ RUBY_SRC_DIR = 'lib'
14
+ RUBY_FILES = FileList[File.join(RUBY_SRC_DIR, '**', '*.rb')]
15
+
16
+ def load_gem(spec)
17
+ eval File.open(spec).readlines.join('')
18
+ end
19
+
20
+ def gem_name(spec)
21
+ gem = load_gem(spec)
22
+ version = gem.version.to_s
23
+ "#{PACKAGE}-#{version}.gem"
24
+ end
25
+
26
+ GEM = gem_name(GEMSPEC)
27
+ CLEAN << [RDOC_OUT_DIR, GEM]
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # Tasks
31
+ # ---------------------------------------------------------------------------
32
+
33
+ task :default => :build
34
+
35
+ desc "Build everything"
36
+ task :build => [:test, :gem, :doc]
37
+
38
+ desc "Synonym for 'build'"
39
+ task :all => :build
40
+
41
+ desc "Build the gem (#{GEM})"
42
+ task :gem => GEM
43
+
44
+ file GEM => RUBY_FILES + ['Rakefile', GEMSPEC] do |t|
45
+ require 'rubygems/builder'
46
+ if !defined? Gem
47
+ raise StandardError.new("Gem package not defined.")
48
+ end
49
+ spec = eval File.new(GEMSPEC).read
50
+ Gem::Builder.new(spec).build
51
+ end
52
+
53
+ desc "Build the documentation, locally"
54
+ task :doc => :rdoc
55
+
56
+ file 'rdoc' => RUBY_FILES do |t|
57
+ require 'rdoc/rdoc'
58
+ puts('Running rdoc...')
59
+ mkdir_p File.dirname(RDOC_OUT_DIR) unless File.exists? RDOC_OUT_DIR
60
+ r = RDoc::RDoc.new
61
+ r.document(['-U', '-m', "#{RUBY_SRC_DIR}/grizzled.rb", '-o', RDOC_OUT_DIR,
62
+ RUBY_SRC_DIR])
63
+ end
64
+
65
+ desc "Install the gem"
66
+ task :install => :gem do |t|
67
+ require 'rubygems/installer'
68
+ puts("Installing from #{GEM}")
69
+ Gem::Installer.new(GEM).install
70
+ end
71
+
72
+ desc "Publish the gem"
73
+ task :publish => :gem do |t|
74
+ sh "gem push #{GEM}"
75
+ end
76
+
77
+ desc "Publish the docs. Not really of use to anyone but the author"
78
+ task :pubdoc => [:pubrdoc, :pubchangelog]
79
+
80
+ task :pubrdoc => :doc do |t|
81
+ target = Pathname.new(RDOC_PUBLISH_DIR).expand_path.to_s
82
+ cd RDOC_OUT_DIR do
83
+ mkdir_p target
84
+ cp_r '.', target
85
+ end
86
+ end
87
+
88
+ desc "Synonym for 'pubchangelog'"
89
+ task :changelog
90
+
91
+ desc "Publish the change log. Not really of use to anyone but the author"
92
+ task :pubchangelog do |t|
93
+ File.open(File.join(GH_PAGES_DIR, 'CHANGELOG.md'), 'w') do |f|
94
+ f.write <<EOF
95
+ ---
96
+ title: Change Log for Grizzled Ruby
97
+ layout: default
98
+ ---
99
+
100
+ EOF
101
+ f.write File.open('CHANGELOG.md').read
102
+ f.close
103
+ end
104
+ end
105
+
106
+ task :pub
107
+
108
+ desc "Alias for 'docpub'"
109
+ task :docpub => :pubdoc
110
+
111
+ desc "Run the unit tests"
112
+ task :test do |t|
113
+ FileList[File.join('test', '**', 't[cs]_*.rb')].each do |tf|
114
+ cd File.dirname(tf) do |dir|
115
+ ruby File.basename(tf)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'grizzled-rails-logger'
4
+ s.version = '0.1.0'
5
+ s.date = '2012-04-12'
6
+ s.summary = 'A custom Rails 3 logger'
7
+ s.authors = ['Brian M. Clapper']
8
+ s.license = 'BSD'
9
+ s.email = 'bmc@clapper.org'
10
+ s.homepage = 'http://software.clapper.org/grizzled-rails-logger'
11
+
12
+ s.description = <<-ENDDESC
13
+ A custom Rails 3 logger
14
+ ENDDESC
15
+
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency('term-ansicolor', '>= 1.0.7')
19
+
20
+ # = MANIFEST =
21
+ s.files = Dir.glob('[A-Z]*')
22
+ s.files += Dir.glob('*.gemspec')
23
+ s.files += Dir.glob('lib/**/*')
24
+ s.files += Dir.glob('rdoc/**/*')
25
+
26
+ # = MANIFEST =
27
+ s.test_files = Dir.glob('test/**/tc_*.rb')
28
+ end
29
+
30
+
data/lib/grizzled.rb ADDED
@@ -0,0 +1,42 @@
1
+ # Grizzled Rails Logger is a Rails 3 custom logger class.
2
+ # See http://software.clapper.org/grizzled-ruby/ for more details.
3
+ #
4
+ # Author:: Brian M. Clapper (mailto:bmc@clapper.org)
5
+ # Copyright:: Copyright (c) 2012 Brian M. Clapper
6
+ # License:: BSD License
7
+ #
8
+ # ---
9
+ #
10
+ # This software is released under a BSD license, adapted from
11
+ # http://opensource.org/licenses/bsd-license.php
12
+ #
13
+ # Copyright (c) 2012, Brian M. Clapper
14
+ # All rights reserved.
15
+ #
16
+ # Redistribution and use in source and binary forms, with or without
17
+ # modification, are permitted provided that the following conditions are
18
+ # met:
19
+ #
20
+ # * Redistributions of source code must retain the above copyright notice,
21
+ # this list of conditions and the following disclaimer.
22
+ #
23
+ # * Redistributions in binary form must reproduce the above copyright
24
+ # notice, this list of conditions and the following disclaimer in the
25
+ # documentation and/or other materials provided with the distribution.
26
+ #
27
+ # * Neither the names "clapper.org", "Grizzled Rails Logger", nor the
28
+ # names of its contributors may be used to endorse or promote products
29
+ # derived from this software without specific prior written permission.
30
+ #
31
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
32
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
35
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ # ---------------------------------------------------------------------------
@@ -0,0 +1,42 @@
1
+ # Grizzled Rails Logger is a Rails 3 custom logger class.
2
+ # See http://software.clapper.org/grizzled-ruby/ for more details.
3
+ #
4
+ # Author:: Brian M. Clapper (mailto:bmc@clapper.org)
5
+ # Copyright:: Copyright (c) 2012 Brian M. Clapper
6
+ # License:: BSD License
7
+ #
8
+ # ---
9
+ #
10
+ # This software is released under a BSD license, adapted from
11
+ # http://opensource.org/licenses/bsd-license.php
12
+ #
13
+ # Copyright (c) 2012, Brian M. Clapper
14
+ # All rights reserved.
15
+ #
16
+ # Redistribution and use in source and binary forms, with or without
17
+ # modification, are permitted provided that the following conditions are
18
+ # met:
19
+ #
20
+ # * Redistributions of source code must retain the above copyright notice,
21
+ # this list of conditions and the following disclaimer.
22
+ #
23
+ # * Redistributions in binary form must reproduce the above copyright
24
+ # notice, this list of conditions and the following disclaimer in the
25
+ # documentation and/or other materials provided with the distribution.
26
+ #
27
+ # * Neither the names "clapper.org", "Grizzled Rails Logger", nor the
28
+ # names of its contributors may be used to endorse or promote products
29
+ # derived from this software without specific prior written permission.
30
+ #
31
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
32
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
35
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ # ---------------------------------------------------------------------------