little_log_friend 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/.gitignore +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +77 -0
- data/Rakefile +26 -0
- data/init.rb +1 -0
- data/lib/little_log_friend/formatter.rb +42 -0
- data/lib/little_log_friend/version.rb +5 -0
- data/lib/little_log_friend.rb +61 -0
- data/little_log_friend.gemspec +26 -0
- data/test/little_log_friend_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 - 2011 Rudolf Schmidt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= LittleLogFriend
|
2
|
+
|
3
|
+
LittleLogFriend sets your standard logger to a more readable format, like so:
|
4
|
+
|
5
|
+
logger = Logger.new STDOUT
|
6
|
+
logger.info 'hello world'
|
7
|
+
# => 2009-01-14 10:10:10 [ INFO] 15356 : hello world
|
8
|
+
|
9
|
+
The format is: DATE TIME [ LOG LEVEL ] PID : MESSAGE
|
10
|
+
|
11
|
+
|
12
|
+
== Installation
|
13
|
+
=== The Gem Version
|
14
|
+
|
15
|
+
gem install little_log_friend
|
16
|
+
|
17
|
+
Or in your Gemfile:
|
18
|
+
|
19
|
+
gem 'little_log_friend'
|
20
|
+
|
21
|
+
You should create an initializer file in order to get LittleLogFriend to work for you, like so:
|
22
|
+
# config/initializers/little_log_friend.rb (create it if not present)
|
23
|
+
require 'little_log_friend
|
24
|
+
|
25
|
+
|
26
|
+
=== The Plugin Version
|
27
|
+
|
28
|
+
script/plugin install git://github.com/rudionrails/little_log_friend.git
|
29
|
+
|
30
|
+
You don't need to specifically require little_log_friend, the init.rb of the plugin will take care of it.
|
31
|
+
|
32
|
+
|
33
|
+
== Usage
|
34
|
+
|
35
|
+
LittleLogFriend will automatically enhance your standard logger with a nicer
|
36
|
+
log formatting - nothing more. Instead of the regular format, you will see
|
37
|
+
every log message starting with a nice timestamp and a better formatted message
|
38
|
+
altogether. This will help you to trace your logs much easier in case something
|
39
|
+
goes happens. Moreover, if you are using monitoring tools to
|
40
|
+
detect errors in you logs so that they send out notifications to your sysadmin,
|
41
|
+
a unified logging format will significantly ease this process.
|
42
|
+
|
43
|
+
Additionally to that, you can add this to your environment.rb:
|
44
|
+
|
45
|
+
LittleLogFriend.colorize!
|
46
|
+
|
47
|
+
This will enable colorized log output (under Unix). Every log level will appear
|
48
|
+
in a different color to ease log interpretation. Here are the colors for each
|
49
|
+
severity:
|
50
|
+
|
51
|
+
debug => green
|
52
|
+
info => white
|
53
|
+
warn => yello
|
54
|
+
error => red
|
55
|
+
fatal => purple
|
56
|
+
unknown => white
|
57
|
+
default => default of the console / none
|
58
|
+
|
59
|
+
|
60
|
+
Also, you can override the default color settings, like so:
|
61
|
+
|
62
|
+
LittleLogFriend.colorize!( :info => "\033[01;36m" ) # cyan for Unix
|
63
|
+
|
64
|
+
Specify the keys as explained above for the default severity colors.
|
65
|
+
|
66
|
+
|
67
|
+
== Additional Notes
|
68
|
+
|
69
|
+
LittleLogFriend is not meant to be a fully featured log solution, but it's
|
70
|
+
supposed to help in the smaller scale and especially when developing.
|
71
|
+
|
72
|
+
Also, you probably don't want to use colorized logging in production mode, as it
|
73
|
+
will be very difficult to read the log file on a remote server with all the color
|
74
|
+
information in it.
|
75
|
+
|
76
|
+
|
77
|
+
Copyright (c) 2009 - 2011 Rudolf Schmidt, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Test the little_log_friend plugin.'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Generate documentation for the little_log_friend plugin.'
|
20
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'LittleLogFriend'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'little_log_friend'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module LittleLogFriend
|
2
|
+
|
3
|
+
class Formatter < Logger::Formatter
|
4
|
+
|
5
|
+
@@colorize = false
|
6
|
+
|
7
|
+
Format = "%s [%5s] %d %s: %s"
|
8
|
+
|
9
|
+
@@colors = {
|
10
|
+
'DEBUG' => "\e[1;32;1m", # green
|
11
|
+
'INFO' => "\e[0;1m", # white
|
12
|
+
'WARN' => "\e[1;33;1m", # yello
|
13
|
+
'ERROR' => "\e[1;31;1m", # red
|
14
|
+
'FATAL' => "\e[1;35;1m", # punk, yes PUNK!
|
15
|
+
'UNKNOWN' => "\e[0;1m", # white
|
16
|
+
'DEFAULT' => "\e[0m" # NONE
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super
|
21
|
+
@datetime_format = "%Y-%m-%d %H:%M:%S"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.colorize!( options = {} )
|
25
|
+
@@colorize = true
|
26
|
+
options.each { |key, value| @@colors[key.to_s.upcase] = value }
|
27
|
+
end
|
28
|
+
|
29
|
+
# This method is invoked when a log event occurs
|
30
|
+
def call ( severity, time, progname, msg )
|
31
|
+
msg = Format % [format_datetime(time), severity, $$, progname, msg2str(msg)]
|
32
|
+
msg = @@colors[severity] + msg + @@colors['DEFAULT'] if @@colorize
|
33
|
+
msg << "\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def number_to_severity ( n )
|
37
|
+
severities = [:debug, :info, :warn, :error, :fatal, :unknown]
|
38
|
+
severities[n]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module LittleLogFriend
|
4
|
+
|
5
|
+
autoload :Formatter, File.dirname(__FILE__) + '/little_log_friend/formatter'
|
6
|
+
|
7
|
+
|
8
|
+
def self.colorize!( *args )
|
9
|
+
Formatter.colorize!( *args )
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# Overload the default logger class
|
15
|
+
class Logger
|
16
|
+
|
17
|
+
alias :old_formatter :formatter if method_defined?(:formatter)
|
18
|
+
|
19
|
+
def formatter
|
20
|
+
@formatter ||= LittleLogFriend::Formatter.new
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
alias :old_format_message :format_message if method_defined?(:format_message)
|
27
|
+
|
28
|
+
def format_message(severity, datetime, progname, msg)
|
29
|
+
(formatter || @default_formatter).call(severity, datetime, progname, msg)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# Overload the BufferedLogger in Rails
|
35
|
+
module ActiveSupport
|
36
|
+
class BufferedLogger
|
37
|
+
|
38
|
+
alias :old_formatter :formatter if method_defined?(:formatter)
|
39
|
+
|
40
|
+
def formatter
|
41
|
+
@formatter ||= LittleLogFriend::Formatter.new
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
alias :old_add :add if method_defined?(:add)
|
46
|
+
|
47
|
+
# We need to overload the add method. Basibally it is the same as the
|
48
|
+
# original one, but we add our own log format to it.
|
49
|
+
def add(severity, message = nil, progname = nil, &block)
|
50
|
+
return if @level > severity
|
51
|
+
message = (message || (block && block.call) || progname).to_s
|
52
|
+
message = formatter.call(formatter.number_to_severity(severity), Time.now.utc, progname, message)
|
53
|
+
message = "#{message}\n" unless message[-1] == ?\n
|
54
|
+
buffer << message
|
55
|
+
auto_flush
|
56
|
+
message
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "little_log_friend/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "little_log_friend"
|
7
|
+
s.version = LittleLogFriend::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rudolf Schmidt"]
|
10
|
+
|
11
|
+
s.homepage = "http://github.com/rudionrails/little_log_friend"
|
12
|
+
|
13
|
+
s.summary = %q{An easy way to set your Ruby standard logger to a more readable format}
|
14
|
+
s.description = %q{LittleLogFriend sets your standard logger to the format: "DATE TIME [ LEVEL ] PID : MESSAGE"}
|
15
|
+
|
16
|
+
s.rubyforge_project = "little_log_friend"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
s.add_development_dependency "activesupport", "~> 2.x"
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: little_log_friend
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rudolf Schmidt
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-23 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rake
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 121
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- x
|
47
|
+
version: 2.x
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: "LittleLogFriend sets your standard logger to the format: \"DATE TIME [ LEVEL ] PID : MESSAGE\""
|
51
|
+
email:
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- LICENSE.txt
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- init.rb
|
65
|
+
- lib/little_log_friend.rb
|
66
|
+
- lib/little_log_friend/formatter.rb
|
67
|
+
- lib/little_log_friend/version.rb
|
68
|
+
- little_log_friend.gemspec
|
69
|
+
- test/little_log_friend_test.rb
|
70
|
+
- test/test_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/rudionrails/little_log_friend
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: little_log_friend
|
101
|
+
rubygems_version: 1.5.0
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: An easy way to set your Ruby standard logger to a more readable format
|
105
|
+
test_files: []
|
106
|
+
|