pluslog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pluslog.rb +35 -0
- metadata +46 -0
data/lib/pluslog.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Object
|
2
|
+
def self.method_added(name)
|
3
|
+
Thread.current[:method] = [self, name]
|
4
|
+
super
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def nil.+@
|
9
|
+
klass, name = Thread.current[:method]
|
10
|
+
method = klass.instance_method(name)
|
11
|
+
klass.send(:define_method, name) do |*args|
|
12
|
+
Pluslogger.log "enter #{name}"
|
13
|
+
Pluslogger.new { method.bind(self).call(*args) }
|
14
|
+
Pluslogger.log "exit #{name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Pluslogger
|
19
|
+
def self.get_pretty_trace(thread = Thread.current)
|
20
|
+
thread[:log_buffer]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.log(string)
|
24
|
+
Thread.current[:log_buffer] ||= ""
|
25
|
+
depth = Thread.current[:depth] || 0
|
26
|
+
Thread.current[:log_buffer] += "#{'| ' * depth}#{string} [#{Time.now}]\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.new(&block)
|
30
|
+
Thread.current[:depth] ||= 0
|
31
|
+
Thread.current[:depth] += 1
|
32
|
+
block.call
|
33
|
+
Thread.current[:depth] -= 1
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pluslog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dmitry Kurilo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple logger gem
|
15
|
+
email: me@masterrr.name
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/pluslog.rb
|
21
|
+
homepage: http://rubygems.org/gems/hola
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Pluslog
|
46
|
+
test_files: []
|