EasyLogger 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/EasyLogger.gemspec +28 -0
- data/EasyLogger.rdoc +62 -0
- data/Gemfile +21 -0
- data/README.rdoc +64 -0
- data/Rakefile +71 -0
- data/bin/EasyLogger +104 -0
- data/doc/ArubaOverrides.html +204 -0
- data/doc/EasyLogger.html +130 -0
- data/doc/EasyLogger/EasyLogger.html +188 -0
- data/doc/EasyLogger_rdoc.html +207 -0
- data/doc/File.html +208 -0
- data/doc/Gemfile.html +123 -0
- data/doc/README_rdoc.html +211 -0
- data/doc/Rakefile.html +136 -0
- data/doc/_index.html +101 -0
- data/doc/bin/EasyLogger.html +62 -0
- data/doc/class_list.html +36 -0
- data/doc/created.rid +11 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +53 -0
- data/doc/css/style.css +310 -0
- data/doc/features/support/env_rb.html +56 -0
- data/doc/file.README.html +60 -0
- data/doc/file_list.html +38 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +60 -0
- data/doc/js/app.js +202 -0
- data/doc/js/full_list.js +149 -0
- data/doc/js/jquery.js +154 -0
- data/doc/lib/EasyLogger_version_rb.html +52 -0
- data/doc/lib/easy_logger/easy_logger_rb.html +52 -0
- data/doc/lib/easy_logger_rb.html +54 -0
- data/doc/method_list.html +43 -0
- data/doc/rdoc.css +706 -0
- data/doc/top-level-namespace.html +88 -0
- data/features/class_filtering.feature +79 -0
- data/features/class_method_filtering.feature +29 -0
- data/features/command_line.feature +25 -0
- data/features/method_filtering.feature +72 -0
- data/features/step_definitions/command_line_steps.rb +1 -0
- data/features/support/env.rb +14 -0
- data/html/EasyLogger.html +170 -0
- data/html/EasyLogger/EasyLogger.html +379 -0
- data/html/File.html +200 -0
- data/html/Logging.html +280 -0
- data/html/README_rdoc.html +212 -0
- data/html/bin/EasyLogger.html +64 -0
- data/html/created.rid +7 -0
- data/html/index.html +198 -0
- data/html/lib/EasyLogger_version_rb.html +52 -0
- data/html/lib/easy_logger/easy_logger_rb.html +54 -0
- data/html/lib/easy_logger/logging_example_rb.html +54 -0
- data/html/lib/easy_logger_rb.html +54 -0
- data/html/rdoc.css +706 -0
- data/lib/EasyLogger_version.rb +3 -0
- data/lib/easy_logger.rb +1 -0
- data/lib/easy_logger/easy_logger.rb +116 -0
- data/lib/easy_logger/logging_example.rb +46 -0
- data/spec/EasyLogger/easy_logger_spec.rb +63 -0
- data/spec/spec_helper.rb +22 -0
- metadata +132 -0
data/lib/easy_logger.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'easy_logger/easy_logger'
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'file/tail'
|
2
|
+
# @author Sylvain Desbureaux
|
3
|
+
module EasyLogger
|
4
|
+
# = Class EasyLogger which will do all the job of matching the lines and showing it
|
5
|
+
# @author Sylvain Desbureaux
|
6
|
+
#
|
7
|
+
# == Attributes
|
8
|
+
# @attr_reader [String] log the log file/stream that we'll look into
|
9
|
+
# @attr_reader [Array] classes the classes to match in the log
|
10
|
+
# @attr_reader [Array] methods the methods to match in the log
|
11
|
+
# @attr_reader [Boolean] verbose the verbosity of the output
|
12
|
+
# @attr_reader [String] separator the separator of the values in the log. it's "|" per default
|
13
|
+
#
|
14
|
+
# == Use
|
15
|
+
# There's two methods to use the class: file() and tail().
|
16
|
+
# Both of them use the same parameters (the attributes of the class).
|
17
|
+
# The log file need to be correctly formatted. the parser assumes that the log file has this format (with '|' as separator in the example):
|
18
|
+
# |some tag (example: the date and time)|some tag|...|class|method| free text
|
19
|
+
# The Separator could be at the end of the free text but never in the middle so choose it carefully!
|
20
|
+
# @see Logging a working logger example
|
21
|
+
#
|
22
|
+
# === File
|
23
|
+
# File will open the stream, parse and output the matching line and exit
|
24
|
+
#
|
25
|
+
# === Tail
|
26
|
+
# Tail will open the end of the stream and parse and output the matching line and exit
|
27
|
+
|
28
|
+
class EasyLogger
|
29
|
+
|
30
|
+
# Display the relevant line of the log matching the classes/methods
|
31
|
+
#
|
32
|
+
# @param [String] log the log file/stream that we'll look into
|
33
|
+
# @param [String] classes the classes to match in the log
|
34
|
+
# @param [String] methods the methods to match in the log
|
35
|
+
# @param [Boolean] verbose the verbosity of the output
|
36
|
+
# @param [String] separator the separator of the values in the log. it's "|" per default
|
37
|
+
def file(log, classes, methods, verbose, separator='|')
|
38
|
+
result = String.new
|
39
|
+
puts "Looking in #{log} I/O for line matching #{classes} classe(s) and #{methods} method(s) with separator '#{separator}'" if verbose && !classes.nil? && !methods.nil?
|
40
|
+
puts "Looking in #{log} I/O for line #{methods} method(s) with separator '#{separator}'" if verbose && classes.nil? && !methods.nil?
|
41
|
+
puts "Looking in #{log} I/O for line matching #{classes} classe(s) with separator '#{separator}'" if verbose && !classes.nil? && methods.nil?
|
42
|
+
puts "Looking in #{log} I/O for all lines" if verbose && classes.nil? && methods.nil?
|
43
|
+
classes =classes.split(',') unless classes.nil?
|
44
|
+
methods =methods.split(',') unless methods.nil?
|
45
|
+
classes.map!{|c| c.downcase} unless classes.nil?
|
46
|
+
methods.map!{|m| m.downcase} unless methods.nil?
|
47
|
+
line_number = 0
|
48
|
+
line_match = 0
|
49
|
+
IO.foreach(log) do |line|
|
50
|
+
line_number += 1
|
51
|
+
if match(line,classes,methods, separator)
|
52
|
+
puts line
|
53
|
+
line_match += 1
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
puts "#{line_match} lines matched on the #{line_number} lines in the log" if verbose
|
58
|
+
end
|
59
|
+
|
60
|
+
# Display the relevant <u>new</u> lines of the log matching the classes/methods
|
61
|
+
#
|
62
|
+
# @param (see EasyLogger#file)
|
63
|
+
def tail(log, classes, methods, verbose, separator='|')
|
64
|
+
result = String.new
|
65
|
+
puts "Tailing in #{log} I/O for line matching #{classes} classe(s) and #{methods} method(s) with separator '#{separator}'" if verbose && !classes.nil? && !methods.nil?
|
66
|
+
puts "Tailing in #{log} I/O for line #{methods} method(s) with separator '#{separator}'" if verbose && classes.nil? && !methods.nil?
|
67
|
+
puts "Tailing in #{log} I/O for line matching #{classes} classe(s) with separator '#{separator}'" if verbose && !classes.nil? && methods.nil?
|
68
|
+
puts "Tailing in #{log} I/O for all lines" if verbose && classes.nil? && methods.nil?
|
69
|
+
classes =classes.split(',') unless classes.nil?
|
70
|
+
methods =methods.split(',') unless methods.nil?
|
71
|
+
classes.map!{|c| c.downcase} unless classes.nil?
|
72
|
+
methods.map!{|m| m.downcase} unless methods.nil?
|
73
|
+
@line_number = 0
|
74
|
+
@line_match = 0
|
75
|
+
# interrupted = false
|
76
|
+
trap("INT") do
|
77
|
+
puts "#{@line_match} lines matched on the #{@line_number} lines in the log" if verbose
|
78
|
+
break
|
79
|
+
end
|
80
|
+
begin
|
81
|
+
File::Tail::Logfile.tail(log) do |line|
|
82
|
+
@line_number += 1
|
83
|
+
if match(line,classes,methods, separator)
|
84
|
+
puts line
|
85
|
+
@line_match += 1
|
86
|
+
end
|
87
|
+
# if interrupted
|
88
|
+
# break
|
89
|
+
# end
|
90
|
+
end
|
91
|
+
rescue
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Verify if a line match the classes/method
|
97
|
+
#
|
98
|
+
# @private
|
99
|
+
# @param [String] line the line to match the regexp
|
100
|
+
# @param classes (see EasyLogger#file)
|
101
|
+
# @param methods (see EasyLogger#file)
|
102
|
+
# @param separator (see EasyLogger#file)
|
103
|
+
# @return [Boolean] True if the line is matched, false if not
|
104
|
+
@private
|
105
|
+
def match(line,classes,methods,separator)
|
106
|
+
unless line[0..-2].split(separator).length < 3
|
107
|
+
methode = line[0..-2].split(separator)[-2].strip.downcase
|
108
|
+
classe = line[0..-2].split(separator)[-3].strip.downcase
|
109
|
+
|
110
|
+
(classes.nil? || classes.include?(classe)) && (methods.nil? || methods.include?(methode))
|
111
|
+
else
|
112
|
+
false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'logger'
|
2
|
+
# @author Sylvain Desbureaux
|
3
|
+
# Most of work grabbed from nuby on rails Hodel 3000 logger
|
4
|
+
# http://nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us.
|
5
|
+
#
|
6
|
+
# I've added the way to retrieve the method which sent the log and the class via caller method.
|
7
|
+
#
|
8
|
+
# I've also taken care to take the next one in caller if the methode is lik each, block,...
|
9
|
+
#
|
10
|
+
# In your environmment file(s) (development.rb, test.rb,...) you'll need to add that in order to use this logger:
|
11
|
+
# @example
|
12
|
+
# require File.dirname(__FILE__) + "/../../app/models/logging"
|
13
|
+
# config.logger = Logging.new(config.paths.log.first )
|
14
|
+
#
|
15
|
+
# And you'll need to put this file (renammed logging.rb here) in app/models folder
|
16
|
+
class Logging < Logger
|
17
|
+
def format_message(severity, timestamp, progname, msg)
|
18
|
+
i = 2
|
19
|
+
methode = caller[i].split('`')[1].split("'")[0]
|
20
|
+
each_true = false
|
21
|
+
puts methode if methode == "each"
|
22
|
+
each_true = true if methode == ""
|
23
|
+
while methode == "debug" || methode == "info" || methode == "error" || methode.split(' ')[0] == "each"
|
24
|
+
i += 1
|
25
|
+
methode = caller[i].split('`')[1].split("'")[0]
|
26
|
+
puts methode if each_true
|
27
|
+
end
|
28
|
+
methode = methode.split(' ')[0] == "block" ? methode.split(' ')[-1].center(17) : methode.center(17)
|
29
|
+
objecte = caller[i].split(':')[0].split('/')[-1].split('.')[0].camelize.center(16)
|
30
|
+
"#{timestamp.strftime("%d %b %H:%M:%S")}|rails[#{$PID}]|#{severity.center(8)}|#{objecte}|#{methode}| #{msg2str(msg).gsub(/\n/, '').lstrip}\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def msg2str(msg)
|
35
|
+
case msg
|
36
|
+
when ::String
|
37
|
+
msg
|
38
|
+
when ::Exception
|
39
|
+
"#{ msg.message } (#{ msg.class }): " <<
|
40
|
+
(msg.backtrace || []).join(" | ")
|
41
|
+
else
|
42
|
+
msg.inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
|
3
|
+
require 'easy_logger'
|
4
|
+
|
5
|
+
describe EasyLogger do
|
6
|
+
before(:each) do
|
7
|
+
@easy_logger = EasyLogger::EasyLogger.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return true with match function when methodes and classes are nil" do
|
11
|
+
line = "{test{test{pouet{pouet"
|
12
|
+
@easy_logger.match(line,nil,nil,"{").should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true with match function when the line match a class and methodes is nil" do
|
16
|
+
line = "RtestRtestRclasseRpouetRpouet"
|
17
|
+
line2 = "RtestRtestR classe RpouetRpouet"
|
18
|
+
@easy_logger.match(line,["classe","autre_classe"],nil,"R").should be_true
|
19
|
+
@easy_logger.match(line2,["classe","autre_classe"],nil,"R").should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return true with match function when the line match a method and classes is nil" do
|
23
|
+
line = "RtestRtestRclasseRMethodeRpouet"
|
24
|
+
line2 = "RtestRtestRclasseR Methode Rpouet"
|
25
|
+
@easy_logger.match(line,nil,["methode", "autre_methode"],"R").should be_true
|
26
|
+
@easy_logger.match(line2,nil,["methode", "autre_methode"],"R").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return true with match function when the line match a class and a method" do
|
30
|
+
line = "RtestRtestRclasseRMethodeRpouet"
|
31
|
+
line2 = "RtestRtestR classe R Methode Rpouet"
|
32
|
+
@easy_logger.match(line,["classe","autre_classe"],["methode", "autre_methode"],"R").should be_true
|
33
|
+
@easy_logger.match(line2,["classe","autre_classe"],["methode", "autre_methode"],"R").should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return true with match function when the line match a class and a method with a separator at the end of the line" do
|
37
|
+
line = "RtestRtestRclasseRMethodeRpouetR"
|
38
|
+
line2 = "RtestRtestR classe R Methode RpouetR"
|
39
|
+
@easy_logger.match(line,["classe","autre_classe"],["methode", "autre_methode"],"R").should be_true
|
40
|
+
@easy_logger.match(line2,["classe","autre_classe"],["methode", "autre_methode"],"R").should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return false with match function when the line match a class but not a method" do
|
44
|
+
line = "RtestRtestRclasseRMethodeRpouetR"
|
45
|
+
line2 = "RtestRtestR classe R Methode RpouetR"
|
46
|
+
@easy_logger.match(line,["classe","autre_classe"],["methodes", "autre_methode"],"R").should be_false
|
47
|
+
@easy_logger.match(line2,["classe","autre_classe"],["methodes", "autre_methode"],"R").should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return false with match function when the line match a method but not a class" do
|
51
|
+
line = "RtestRtestRclasseRMethodeRpouetR"
|
52
|
+
line2 = "RtestRtestR classe R Methode RpouetR"
|
53
|
+
@easy_logger.match(line,["classes","autre_classe"],["methode", "autre_methode"],"R").should be_false
|
54
|
+
@easy_logger.match(line2,["classes","autre_classe"],["methode", "autre_methode"],"R").should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false if the separator is not found in the line" do
|
58
|
+
line ="13456"
|
59
|
+
@easy_logger.match(line,["classes","autre_classe"],["methode", "autre_methode"],"R").should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#require 'cover_me'
|
2
|
+
#require File.join(File.expand_path(File.dirname(__FILE__)), "..", "coverage", "cover_me_config")
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
Rspec.configure do |config|
|
6
|
+
# == Mock Framework
|
7
|
+
#
|
8
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
9
|
+
#
|
10
|
+
# config.mock_with :mocha
|
11
|
+
# config.mock_with :flexmock
|
12
|
+
# config.mock_with :r
|
13
|
+
config.expect_with :rspec
|
14
|
+
config.mock_with :rspec
|
15
|
+
|
16
|
+
#config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
17
|
+
|
18
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
19
|
+
# examples within a transaction, comment the following line or assign false
|
20
|
+
# instead of true.
|
21
|
+
#config.use_transactional_fixtures = false
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: EasyLogger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Sylvain Desbureaux
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-16 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
EasyLogger permit to filter in lines in logs, allowing to
|
23
|
+
view only the inputs you want based on Class or Method
|
24
|
+
email:
|
25
|
+
- sylvain@desbureaux.fr
|
26
|
+
executables:
|
27
|
+
- EasyLogger
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
- EasyLogger.rdoc
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- EasyLogger.gemspec
|
36
|
+
- EasyLogger.rdoc
|
37
|
+
- Gemfile
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- bin/EasyLogger
|
41
|
+
- doc/ArubaOverrides.html
|
42
|
+
- doc/EasyLogger.html
|
43
|
+
- doc/EasyLogger/EasyLogger.html
|
44
|
+
- doc/EasyLogger_rdoc.html
|
45
|
+
- doc/File.html
|
46
|
+
- doc/Gemfile.html
|
47
|
+
- doc/README_rdoc.html
|
48
|
+
- doc/Rakefile.html
|
49
|
+
- doc/_index.html
|
50
|
+
- doc/bin/EasyLogger.html
|
51
|
+
- doc/class_list.html
|
52
|
+
- doc/created.rid
|
53
|
+
- doc/css/common.css
|
54
|
+
- doc/css/full_list.css
|
55
|
+
- doc/css/style.css
|
56
|
+
- doc/features/support/env_rb.html
|
57
|
+
- doc/file.README.html
|
58
|
+
- doc/file_list.html
|
59
|
+
- doc/frames.html
|
60
|
+
- doc/index.html
|
61
|
+
- doc/js/app.js
|
62
|
+
- doc/js/full_list.js
|
63
|
+
- doc/js/jquery.js
|
64
|
+
- doc/lib/EasyLogger_version_rb.html
|
65
|
+
- doc/lib/easy_logger/easy_logger_rb.html
|
66
|
+
- doc/lib/easy_logger_rb.html
|
67
|
+
- doc/method_list.html
|
68
|
+
- doc/rdoc.css
|
69
|
+
- doc/top-level-namespace.html
|
70
|
+
- features/class_filtering.feature
|
71
|
+
- features/class_method_filtering.feature
|
72
|
+
- features/command_line.feature
|
73
|
+
- features/method_filtering.feature
|
74
|
+
- features/step_definitions/command_line_steps.rb
|
75
|
+
- features/support/env.rb
|
76
|
+
- html/EasyLogger.html
|
77
|
+
- html/EasyLogger/EasyLogger.html
|
78
|
+
- html/File.html
|
79
|
+
- html/Logging.html
|
80
|
+
- html/README_rdoc.html
|
81
|
+
- html/bin/EasyLogger.html
|
82
|
+
- html/created.rid
|
83
|
+
- html/index.html
|
84
|
+
- html/lib/EasyLogger_version_rb.html
|
85
|
+
- html/lib/easy_logger/easy_logger_rb.html
|
86
|
+
- html/lib/easy_logger/logging_example_rb.html
|
87
|
+
- html/lib/easy_logger_rb.html
|
88
|
+
- html/rdoc.css
|
89
|
+
- lib/EasyLogger_version.rb
|
90
|
+
- lib/easy_logger.rb
|
91
|
+
- lib/easy_logger/easy_logger.rb
|
92
|
+
- lib/easy_logger/logging_example.rb
|
93
|
+
- spec/EasyLogger/easy_logger_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: ""
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --title
|
102
|
+
- EasyLogger
|
103
|
+
- --main
|
104
|
+
- README.rdoc
|
105
|
+
- -ri
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project: EasyLogger
|
127
|
+
rubygems_version: 1.3.7
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: EasyLogger permit to filter in lines in logs
|
131
|
+
test_files: []
|
132
|
+
|