formatted_rails_logger 0.1.0 → 0.2.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.
data/README.markdown
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
Monkey-patches Rails BufferedLogger (the standard Rails logger) to accept a formatter just like ruby Logger does. Provides a formatter that includes timestamp and severity in logs, while taking account of Rails habit of making space in the logfile by adding newlines to the beginning of log message.
|
4
4
|
|
5
|
-
It's only 80 lines of verbose code.
|
5
|
+
It's only 80 lines of verbose code. (yes, this readme is longer than the source) I'd think a bazillion people would have done this before, but I didn't see any other gems to do it simply and flexibly, sorry for any duplication.
|
6
6
|
|
7
7
|
## How to use
|
8
8
|
|
9
|
-
|
9
|
+
Version 0.1.0 should work for both Rails2 and Rails 3.0.x - 3.1.x
|
10
|
+
|
11
|
+
Version 0.2.0 for Rails 3.2.0 -- will future versions of Rails 3.2.x again change internal logger implementation to break this? Who knows! Why doesn't Rails just support #formatter for us? Who knows! At least 3.2.0 made it a lot easier to patch in, with an internal stdlib Logger at the bottom of things.
|
10
12
|
|
11
13
|
Include the formatted_rails_logger gem in your project as appropriate for your Rails version.
|
12
14
|
|
@@ -45,9 +47,9 @@ I did use a regexp to look for newlines at the very beginning of a log message,
|
|
45
47
|
|
46
48
|
* Why has Rails always thought it better to exclude timestamps and severity from logfiles? Me, I need to be able to grep logfiles for "ERROR" or "FATAL" or "WARN" to see how my app's doing, and I need to be able to have timestamps to correlate human observed problems to the logs. Am I really alone here?
|
47
49
|
|
48
|
-
* Why does Rails BufferedLogger not provide the same formatter functionality
|
50
|
+
* Why does Rails BufferedLogger not provide the same #formatter functionality as ruby Logger, either by sub-classing Logger, or duck-typing the formatter functionality too? (But, hey, it's better than Rails <=2.2, where Rails monkey patched ruby Logger to ignore it's #formatter, huh?)
|
49
51
|
|
50
|
-
* Why does ruby 1.8.7 Time.strftime not accept an %L formatting string, even though the [documentation](http://www.ruby-doc.org/core/classes/Time.html#M000392) says it should? Did they fix this in 1.9? I don't know.
|
52
|
+
* Why does ruby 1.8.7 Time.strftime not accept an %L formatting string, even though the [documentation](http://www.ruby-doc.org/core/classes/Time.html#M000392) says it should? Did they fix this in 1.9? I don't know. For that matter, why does ruby Time give you a method to get microseconds, but a not method to get miliseconds?
|
51
53
|
|
52
54
|
## Things I didn't do
|
53
55
|
|
@@ -11,6 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{Formatting capabilities for Rails BufferedLogger}
|
12
12
|
|
13
13
|
s.rubyforge_project = "formatted_rails_logger"
|
14
|
+
|
15
|
+
s.add_dependency "rails", "~> 3.2.0"
|
14
16
|
|
15
17
|
s.files = `git ls-files`.split("\n")
|
16
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -2,50 +2,29 @@
|
|
2
2
|
# doing this rather than declaring Rails a dependency.
|
3
3
|
ActiveSupport::BufferedLogger.class
|
4
4
|
|
5
|
+
# Rails 3.2 BufferedLogger has an internal @logger with a stdlib rails
|
6
|
+
# logger, but it doesn't expose ability to set a formatter. We've just
|
7
|
+
# got to do that, no problem.
|
5
8
|
class ActiveSupport::BufferedLogger
|
6
9
|
attr_accessor :formatter
|
7
10
|
# use pure ruby class method, Rails provides ones with
|
8
11
|
# better semantics for inheritance, but they keep changing
|
9
12
|
# version to version, so nope.
|
10
13
|
class << self ; attr_accessor :default_formatter ; end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# Have to over-ride/replace BufferedLogger's usual #add
|
16
|
-
# to use formatter
|
17
|
-
def add(severity, message = nil, progname = nil, &block)
|
18
|
-
return if @level > severity
|
19
|
-
message = (message || (block && block.call) || progname).to_s
|
20
|
-
|
21
|
-
# our custom formatting
|
22
|
-
message = format_message(format_severity(severity), Time.now, progname, message)
|
23
|
-
|
24
|
-
# If a newline is necessary then create a new message ending with a newline.
|
25
|
-
# Ensures that the original message is not mutated.
|
26
|
-
message = "#{message}\n" unless message[-1] == ?\n
|
27
|
-
buffer << message
|
28
|
-
auto_flush
|
29
|
-
message
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super(*args)
|
17
|
+
@log.formatter = self.class.default_formatter if self.class.default_formatter
|
30
18
|
end
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
# why does BufferedLogger not give us a way to translate from integer
|
35
|
-
# constant to actual severity lable? argh. copied from Logger
|
36
|
-
# Severity label for logging. (max 5 char)
|
37
|
-
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL UNKNOWN)
|
38
|
-
def format_severity(severity)
|
39
|
-
SEV_LABEL[severity] || 'UNKNOWN'
|
20
|
+
def formatter=(formatter)
|
21
|
+
@log.formatter = formatter
|
40
22
|
end
|
41
23
|
|
42
|
-
def
|
43
|
-
|
44
|
-
formatter.call(severity, datetime, progname, msg)
|
45
|
-
else
|
46
|
-
msg
|
47
|
-
end
|
24
|
+
def formatter
|
25
|
+
@log.formatter
|
48
26
|
end
|
27
|
+
|
49
28
|
|
50
29
|
end
|
51
30
|
|
@@ -7,7 +7,11 @@ class FormattedRailsLogger::Formatter
|
|
7
7
|
@@format_str = "[%s] %5s %s"
|
8
8
|
@@datetime_format = nil
|
9
9
|
|
10
|
-
def call(severity, time, progname, msg)
|
10
|
+
def call(severity, time, progname, msg)
|
11
|
+
# Rails 3.2 seems to automatically add a newline, for consistency
|
12
|
+
# we will too.
|
13
|
+
msg += "\n"
|
14
|
+
|
11
15
|
# see no need for micro-seconds like in Logger, milis suffices.
|
12
16
|
# No idea why documented %L and other such useful things
|
13
17
|
# do not work in strftime.
|
metadata
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatted_rails_logger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jonathan Rochkind
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-01-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &244305560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *244305560
|
22
25
|
description:
|
23
|
-
email:
|
26
|
+
email:
|
24
27
|
- jonathan@dnil.net
|
25
28
|
executables: []
|
26
|
-
|
27
29
|
extensions: []
|
28
|
-
|
29
30
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
31
|
+
files:
|
32
32
|
- .gitignore
|
33
33
|
- Gemfile
|
34
34
|
- README.markdown
|
@@ -38,39 +38,28 @@ files:
|
|
38
38
|
- lib/formatted_rails_logger/buffered_logger_inject.rb
|
39
39
|
- lib/formatted_rails_logger/formatter.rb
|
40
40
|
- lib/formatted_rails_logger/version.rb
|
41
|
-
has_rdoc: true
|
42
41
|
homepage: https://github.com/jrochkind/formatted_rails_logger
|
43
42
|
licenses: []
|
44
|
-
|
45
43
|
post_install_message:
|
46
44
|
rdoc_options: []
|
47
|
-
|
48
|
-
require_paths:
|
45
|
+
require_paths:
|
49
46
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
48
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
54
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
version: "0"
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
68
59
|
requirements: []
|
69
|
-
|
70
60
|
rubyforge_project: formatted_rails_logger
|
71
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.8.10
|
72
62
|
signing_key:
|
73
63
|
specification_version: 3
|
74
64
|
summary: Formatting capabilities for Rails BufferedLogger
|
75
65
|
test_files: []
|
76
|
-
|