tagged_logger 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009, Fedor Kocherga <fkocherga@gmail.com>
1
+ Copyright (c) 2010, Aleksandr Furmanov <aleksandr.furmanov@gmail.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.markdown CHANGED
@@ -12,7 +12,7 @@ day you'll need something more sophisticated, like several log files each servin
12
12
  different components and for different audience.
13
13
 
14
14
  ## Installation
15
- $ sudo gem install tagged_logger --source=http://gemcutter.org
15
+ $ gem install tagged_logger
16
16
 
17
17
  ## Usage
18
18
 
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
3
 
5
4
  Rake::TestTask.new do |t|
6
5
  t.libs << "test"
@@ -8,17 +7,6 @@ Rake::TestTask.new do |t|
8
7
  t.verbose = true
9
8
  end
10
9
 
11
- begin
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |s|
14
- s.name = "tagged_logger"
15
- s.summary = "Detaches _what_ is logged from _how_ it is logged."
16
- s.email = "fkocherga@gmail.com"
17
- s.homepage = "http://github.com/fkocherga/tagged_logger"
18
- s.authors = ["Fedor Kocherga"]
19
- s.test_files = ['test/test.rb', 'test/test_examples.rb']
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
24
- end
10
+ task :default => "test"
11
+
12
+
data/lib/tagged_logger.rb CHANGED
@@ -14,7 +14,7 @@ class TaggedLogger
14
14
  end
15
15
 
16
16
  def rules(&block)
17
- add_logger_generator_in_Kernel
17
+ add_logger_generator_in_Object
18
18
  instance_eval(&block)
19
19
  end
20
20
 
@@ -119,9 +119,9 @@ class TaggedLogger
119
119
  end
120
120
  end
121
121
 
122
- def add_logger_generator_in_Kernel
123
- return if Kernel.respond_to?(:logger, true) #no harm
124
- Kernel.class_eval do
122
+ def add_logger_generator_in_Object
123
+ return if Object.respond_to?(:logger, true) #no harm
124
+ Object.class_eval do
125
125
  def logger
126
126
  klass = self.class == Class ? self : self.class
127
127
  result = klass.class_eval do
data/test/test.rb CHANGED
@@ -24,13 +24,14 @@ class TaggedLoggerTest < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  teardown do
27
- Kernel.class_eval { remove_method :logger }
27
+ Object.class_eval { remove_method :logger }
28
28
  end
29
29
 
30
30
  should "be able to intialize with minimal effort, without defining any rules" do
31
31
  TaggedLogger.init
32
32
  dont_allow(@@stub_out).write
33
- assert Class.new.methods.include? "logger"
33
+ logger_method = RUBY_VERSION >= '1.9' ? :logger : "logger"
34
+ assert Class.new.methods.include? logger_method
34
35
  assert_nothing_raised { Class.new.logger }
35
36
  end
36
37
 
metadata CHANGED
@@ -1,84 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagged_logger
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 1
9
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
10
11
  platform: ruby
11
12
  authors:
12
- - Fedor Kocherga
13
+ - Aleksandr Furmanov
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-30 00:00:00 -05:00
18
+ date: 2010-09-28 00:00:00 -05:00
18
19
  default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: fkocherga@gmail.com
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: facets
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: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rr
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: Detaches _what_ is logged from _how_ it is logged
64
+ email:
65
+ - aleksandr.furmanov@gmail.com
23
66
  executables: []
24
67
 
25
68
  extensions: []
26
69
 
27
- extra_rdoc_files:
28
- - README.html
29
- - README.markdown
70
+ extra_rdoc_files: []
71
+
30
72
  files:
31
- - .gitignore
32
73
  - CHANGES.markdown
33
74
  - MIT-LICENSE
34
- - README.markdown
35
75
  - Rakefile
76
+ - README.markdown
36
77
  - VERSION
78
+ - lib/tagged_logger.rb
79
+ - test/expected_examples_output.txt
80
+ - test/test.rb
81
+ - test/test_examples.rb
82
+ - test/test_performance.rb
37
83
  - examples/changing_format.rb
38
84
  - examples/one_log_per_classes.rb
39
85
  - examples/one_tag_per_classes.rb
40
86
  - examples/per_class_customization.rb
41
87
  - examples/rule_with_regex.rb
42
88
  - examples/simplest_usage.rb
43
- - lib/tagged_logger.rb
44
- - tagged_logger.gemspec
45
- - tagged_logger.rb
46
- - test/expected_examples_output.txt
47
- - test/test.rb
48
- - test/test_examples.rb
49
- - test/test_performance.rb
50
- - todo.txt
51
- - README.html
52
89
  has_rdoc: true
53
- homepage: http://github.com/fkocherga/tagged_logger
90
+ homepage: http://github.com/afurmanov/tagged_logger
54
91
  licenses: []
55
92
 
56
93
  post_install_message:
57
- rdoc_options:
58
- - --charset=UTF-8
94
+ rdoc_options: []
95
+
59
96
  require_paths:
60
97
  - lib
61
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
62
100
  requirements:
63
101
  - - ">="
64
102
  - !ruby/object:Gem::Version
103
+ hash: 3
65
104
  segments:
66
105
  - 0
67
106
  version: "0"
68
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
69
109
  requirements:
70
110
  - - ">="
71
111
  - !ruby/object:Gem::Version
112
+ hash: 23
72
113
  segments:
73
- - 0
74
- version: "0"
114
+ - 1
115
+ - 3
116
+ - 6
117
+ version: 1.3.6
75
118
  requirements: []
76
119
 
77
120
  rubyforge_project:
78
- rubygems_version: 1.3.6
121
+ rubygems_version: 1.3.7
79
122
  signing_key:
80
123
  specification_version: 3
81
- summary: Detaches _what_ is logged from _how_ it is logged.
82
- test_files:
83
- - test/test.rb
84
- - test/test_examples.rb
124
+ summary: Detaches _what_ is logged from _how_ it is logged
125
+ test_files: []
126
+
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- pkg
2
- doc
3
- Manifest
4
- README.html
5
- CHANGES.html
6
- *.log
data/README.html DELETED
@@ -1,130 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!DOCTYPE html PUBLIC
3
- "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
4
- "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
5
- <html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
6
- <head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>TaggedLogger</title></head>
7
- <body>
8
- <h1 id='taggedlogger'>TaggedLogger</h1>
9
-
10
- <p>Detaches <strong>what</strong> is logged from <strong>how</strong> it is logged.</p>
11
-
12
- <h2 id='what_is_it_for'>What is it for?</h2>
13
-
14
- <p>Every time you want to log something, simply write:</p>
15
-
16
- <pre><code>logger.debug(&quot;verbose debug information&quot;) #warn, #info, #error, #fatal also works</code></pre>
17
-
18
- <p>and do not worry about what kind of logger you use and how your code accesses it. You may configure these things later, one day writing to STDOUT works for you, another day you&#8217;ll need something more sophisticated, like several log files each serving different components and for different audience.</p>
19
-
20
- <h2 id='installation'>Installation</h2>
21
-
22
- <pre><code>$ sudo gem install tagged_logger --source=http://gemcutter.org</code></pre>
23
-
24
- <h2 id='usage'>Usage</h2>
25
-
26
- <p>After specifying some logging rules:</p>
27
-
28
- <pre><code>TaggedLogger.rules do
29
- info A, :to =&gt; Logger.new(&quot;log_for_A_class.log&quot;) #1 rule
30
- error /.*/, :to =&gt; Logger.new(ERROR) #2 rule
31
- info /.*/, :to =&gt; Logger.new(STDOUT) #3 rule
32
- end</code></pre>
33
-
34
- <p>the following will happen:</p>
35
-
36
- <ol>
37
- <li>
38
- <p>The <em>#logger()</em> method becomes available <strong>everywhere</strong>, so it is completely safe to have a code like:</p>
39
-
40
- <pre><code> class A
41
- def foo
42
- logger.info(&quot;Something interesting happened in A#foo&quot;) #goes to STDOUT and to &#39;log_for_A_class.log&#39; file
43
- logger.debug(&quot;I want to see some details.&quot;) #goes nowhere
44
- end
45
- end
46
- logger.error(&quot;#logger is available everywhere&quot;) #goes to STDERR
47
- class B
48
- logger.warn(&quot;#logger is available everywhere&quot;) #goes to STDOUT
49
- end </code></pre>
50
- </li>
51
-
52
- <li>
53
- <p>The A&#8217;s <em>logger.info()</em> output will show up in two destinations:</p>
54
-
55
- <ul>
56
- <li>
57
- <p>in STDOUT, as defined by rule #3</p>
58
- </li>
59
-
60
- <li>
61
- <p>in &#8216;log_for_A_class.log&#8217; file, as defined by rule #1</p>
62
- </li>
63
- </ul>
64
- </li>
65
-
66
- <li>
67
- <p>From <strong>wherever</strong> it gets called from:</p>
68
-
69
- <pre><code> logger.error(&quot;ERROR&quot;) #will print &#39;ERROR&#39; in standard error
70
- logger.info(&quot;INFO&quot;) #will print &#39;INFO&#39; in standard output
71
- logger.debug(&quot;DEBUG&quot;) #will not print anything, since there is no &#39;debug&#39; rule</code></pre>
72
- </li>
73
- </ol>
74
-
75
- <p>The <em>#logger()</em> returns some object having methods: <em>#debug(), #info(), #warn(), #error() and #fatal()</em>. These method have generated on first <em>#logger()</em> call and contain only necessary code to meet rules. It means, for example, that if no rules defined all these methods do nothing. It is done for performance reasons, I like to log a lot and I do not want calls like <em>#logger.debug()</em> slowing down production code.</p>
76
-
77
- <p>The simplest way to have a <em>#logger()</em> available everywhere without specifying any rules is:</p>
78
-
79
- <pre><code>TaggedLogger.init</code></pre>
80
-
81
- <p>No rules specified, therefore whenever you call <em>logger.debug()</em> (or alike) you actually paying for just an empty method execution. You may specify rules later, now you may stay focused on code you are writing.</p>
82
-
83
- <p>You may define your own formatting:</p>
84
-
85
- <pre><code>TaggedLogger.rules do
86
- format {|level, tag, message| &quot;#{level}-#{tag}: #{msg}&quot;}
87
- end</code></pre>
88
-
89
- <p>Each <em>#format()</em> call overrides previous format. If you are wondering what the heck the &#8216;tag&#8217; is - the answer is simple. The tag is a class name whose method calls <em>#logger()</em>. This is what allows to specify rules for classes or namespaces and this is what the <em>tagged_logger</em> plugin is named after.</p>
90
-
91
- <p>Lets see how you may use it. For example you want to have separate log files for classes <em>Network</em> and <em>Database</em>:</p>
92
-
93
- <pre><code>TaggedLogger.rules do
94
- debug Network, :to =&gt; Logger.new(&quot;network.log&quot;)
95
- debug Database, :to =&gt; Logger.new(&quot;database.log&quot;)
96
- end</code></pre>
97
-
98
- <p>In case you want to define common log for several classes:</p>
99
-
100
- <pre><code>TaggedLogger.rules do
101
- debug [Ftp, Http, Sockets], :to =&gt; Logger.new(&quot;network.log&quot;)
102
- end </code></pre>
103
-
104
- <p>Or if you want to have all these classes showing up under common tag <em>Network</em> in standard output:</p>
105
-
106
- <pre><code>TaggedLogger.rules do
107
- info /.*/, :to =&gt; Logger.new(STDOUT)
108
- rename [Ftp, Http, Sockets] =&gt; :Network
109
- end</code></pre>
110
-
111
- <p>You may also use regular expressions in your rules:</p>
112
-
113
- <pre><code>TaggedLogger.rules do
114
- info /Active::/, :to =&gt; Logger.new(&quot;active.log&quot;)
115
- end</code></pre>
116
-
117
- <h2 id='license'>License</h2>
118
-
119
- <p><em>TaggedLogger</em> is released under the MIT license.</p>
120
-
121
- <h2 id='shortcomings'>Shortcomings</h2>
122
-
123
- <p>The <em>#info(), #debug(), #warn(), #error(), #fatal()</em> rules when have form like <em>:to =&gt; logger</em>, the <em>logger</em> <strong>has</strong> to be an object of standard library <em>Logger</em> class. If you need to use different sort of logger the more general rules form could is:</p>
124
-
125
- <pre><code>TaggedLogger.rules do
126
- info /Whatever/ do |level, tag, message|
127
- #do your special logging here
128
- end
129
- end</code></pre>
130
- </body></html>
@@ -1,60 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{tagged_logger}
8
- s.version = "0.3.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Fedor Kocherga"]
12
- s.date = %q{2010-03-30}
13
- s.email = %q{fkocherga@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.html",
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "CHANGES.markdown",
21
- "MIT-LICENSE",
22
- "README.markdown",
23
- "Rakefile",
24
- "VERSION",
25
- "examples/changing_format.rb",
26
- "examples/one_log_per_classes.rb",
27
- "examples/one_tag_per_classes.rb",
28
- "examples/per_class_customization.rb",
29
- "examples/rule_with_regex.rb",
30
- "examples/simplest_usage.rb",
31
- "lib/tagged_logger.rb",
32
- "tagged_logger.gemspec",
33
- "tagged_logger.rb",
34
- "test/expected_examples_output.txt",
35
- "test/test.rb",
36
- "test/test_examples.rb",
37
- "test/test_performance.rb",
38
- "todo.txt"
39
- ]
40
- s.homepage = %q{http://github.com/fkocherga/tagged_logger}
41
- s.rdoc_options = ["--charset=UTF-8"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.6}
44
- s.summary = %q{Detaches _what_ is logged from _how_ it is logged.}
45
- s.test_files = [
46
- "test/test.rb",
47
- "test/test_examples.rb"
48
- ]
49
-
50
- if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
- else
56
- end
57
- else
58
- end
59
- end
60
-
data/tagged_logger.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + '/lib/tagged_logger.rb'
data/todo.txt DELETED
@@ -1,34 +0,0 @@
1
- * figure out how profiling info could be displayed on New Relic
2
- May be:
3
-
4
- instrument object, :method
5
-
6
- monkey patchs method with
7
-
8
- logger.debug("MethodName()/started")
9
- ...
10
- logger.debug("MethodName()/stopped")
11
-
12
-
13
- create special logger for instrumentation:
14
- StatisticsLogger
15
-
16
- so somebody may write:
17
-
18
- instrument object, :method, :to => StatisticsLogger.new( file, :interval => 100 )
19
- #may be not a file, but mongodb connection
20
-
21
- instrument object, :method, :to => NewRelicLogger.new
22
-
23
- The StatisticsLogger is for monitoring/troubleshouting, it supposed to help answer questions like:
24
- - how my app behaves in average
25
-
26
- The NewRelicLogger simply redirects all sampling to newrelic_rpm
27
-
28
- - logger.debug method (and alike) should accept block for performance reason
29
- - writing messages in any encoding
30
- - test against 'logging' framework
31
- - test agains 1.9.1
32
- - test agains 1.8.6 (really?)
33
- - test with Rails
34
- - when logger specified in :to => ... then lib must complain unless formatting and logging code to that specific logger class was not defined