slogger 0.0.1 → 0.0.2

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.rdoc CHANGED
@@ -4,11 +4,11 @@ Slogger is a Ruby library to help work with standard Ruby Syslog library.
4
4
 
5
5
  == Features
6
6
 
7
- === 1. Slogger::Logger
7
+ === Slogger::Logger
8
8
 
9
9
  A more friendly wrapper on Ruby's Syslog.
10
10
 
11
- Sample:
11
+ Sample: simple message log
12
12
 
13
13
  slogger = Slogger::Logger.new "sample_app", :debug, :local0
14
14
  slogger.info "A good info"
@@ -16,7 +16,16 @@ Sample:
16
16
 
17
17
  # and after, look at the syslog file of your SO ;)
18
18
 
19
- === 2. Slogger::Rack::RequestLogger
19
+ Sample: message log preceded by spent time
20
+
21
+ slogger = Slogger::Logger.new "sample_app", :debug, :local0
22
+ slogger.info "A really good info preceded by spent time" do
23
+ # do something
24
+ end
25
+
26
+ # and after, look at the syslog file of your SO ;)
27
+
28
+ === Slogger::Rack::RequestLogger
20
29
 
21
30
  A Rack middleware to log incoming requests.
22
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -63,19 +63,27 @@ module Slogger
63
63
  @facility_as_int = FACILITY[facility]
64
64
  end
65
65
 
66
- def method_missing(name, *args)
67
- if LEVEL.key? name
68
- log(name, args[0])
69
- else
70
- super name, *args
66
+ LEVEL.each_key do |level|
67
+ define_method level do |message, &block|
68
+ log(level, message, &block)
71
69
  end
72
70
  end
73
71
 
74
72
  private
75
73
 
76
- def log(level, message)
74
+ def log(level, message, &block)
77
75
  return if LEVEL[level] > @level_as_int
78
76
 
77
+ if block_given?
78
+ began_at = Time.now
79
+
80
+ yield
81
+
82
+ now = Time.now
83
+ end_at = now - began_at
84
+ message = "[#{end_at}s] #{message}"
85
+ end
86
+
79
87
  Syslog.open(@app_name, Syslog::LOG_PID, @facility_as_int) { |s| s.send level, message }
80
88
  end
81
89
  end
@@ -40,4 +40,14 @@ describe Slogger::Logger do
40
40
  subject.info "INFO message"
41
41
  end
42
42
  end
43
+
44
+ describe "when a block is passed to log method" do
45
+ subject { Slogger::Logger.new "test_app", :debug, :local0 }
46
+
47
+ it "it should add spent time to the message" do
48
+ subject.info "a block wrapped by log" do
49
+ sleep(10)
50
+ end
51
+ end
52
+ end
43
53
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slogger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Leandro Silva
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 -02:00
18
+ date: 2011-02-18 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency