pangdudu-rofl 0.1
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 +38 -0
- data/bin/rofl +25 -0
- data/lib/rofl.rb +64 -0
- data/lib/rofl_trace.rb +26 -0
- data/lib/test_rofl.rb +24 -0
- metadata +57 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
= ROFL
|
|
2
|
+
|
|
3
|
+
My little logger wrapper. Will give you easy access to logger functions with
|
|
4
|
+
class and caller method info.
|
|
5
|
+
|
|
6
|
+
rofl,lol.
|
|
7
|
+
|
|
8
|
+
== Installation
|
|
9
|
+
|
|
10
|
+
sudo gem install pangdudu-rofl --source=http://gems.github.com
|
|
11
|
+
|
|
12
|
+
== Usage
|
|
13
|
+
|
|
14
|
+
look at the test_rofl.rb or simply do this:
|
|
15
|
+
|
|
16
|
+
require 'rubygems'
|
|
17
|
+
require 'rofl'
|
|
18
|
+
include Rofl
|
|
19
|
+
|
|
20
|
+
you can than use the methods: elog,wlog,ilog,dlog
|
|
21
|
+
|
|
22
|
+
where elog is like:
|
|
23
|
+
logger.error (text if you like)
|
|
24
|
+
wlog is like:
|
|
25
|
+
logger.warning (text if you like)
|
|
26
|
+
ilog is like:
|
|
27
|
+
logger.info (text if you like)
|
|
28
|
+
dlog is like:
|
|
29
|
+
logger.debug (text if you like)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
== Rule the universe!
|
|
33
|
+
|
|
34
|
+
Log,log,log.
|
|
35
|
+
|
|
36
|
+
== License
|
|
37
|
+
|
|
38
|
+
GPL -> http://www.gnu.org/licenses/gpl.txt
|
data/bin/rofl
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
require 'rofl'
|
|
3
|
+
include Rofl
|
|
4
|
+
|
|
5
|
+
class Test
|
|
6
|
+
def initialize
|
|
7
|
+
dlog "initialize"
|
|
8
|
+
end
|
|
9
|
+
def call_hello_world
|
|
10
|
+
other_method
|
|
11
|
+
hello_world
|
|
12
|
+
other_method
|
|
13
|
+
end
|
|
14
|
+
def hello_world
|
|
15
|
+
other_method
|
|
16
|
+
dlog "hello world!"
|
|
17
|
+
other_method
|
|
18
|
+
end
|
|
19
|
+
def other_method
|
|
20
|
+
puts "puts git other method called"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test = Test.new
|
|
25
|
+
test.call_hello_world
|
data/lib/rofl.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
|
|
3
|
+
#little happy logger module
|
|
4
|
+
module Rofl
|
|
5
|
+
|
|
6
|
+
attr_accessor :debugname,:logger
|
|
7
|
+
|
|
8
|
+
#check if there already is a logger, kind of a constructor
|
|
9
|
+
def rofl_logger_check
|
|
10
|
+
if @logger.nil?
|
|
11
|
+
#to stop output from getting messy, we use a logger
|
|
12
|
+
@logger = Logger.new(STDOUT)
|
|
13
|
+
@logger.level = Logger::DEBUG
|
|
14
|
+
#@logger.datetime_format = "%Y-%m-%d %H:%M:%S" #useful for logging to a file
|
|
15
|
+
@logger.datetime_format = "%H:%M:%S" #useful for debugging
|
|
16
|
+
@debugname = self.class if @debugname.nil? #only used to inform the user
|
|
17
|
+
@tracing = false
|
|
18
|
+
#enable tracing
|
|
19
|
+
if @tracing
|
|
20
|
+
require 'rofl_trace'
|
|
21
|
+
include RoflTrace
|
|
22
|
+
rofl_enable_trace
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
#error message
|
|
27
|
+
def elog text="error"
|
|
28
|
+
rofl_logger_check #check if logger is setup
|
|
29
|
+
@logger.error "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
|
|
30
|
+
end
|
|
31
|
+
#warning
|
|
32
|
+
def wlog text="warning"
|
|
33
|
+
rofl_logger_check #check if logger is setup
|
|
34
|
+
@logger.warning "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
|
|
35
|
+
end
|
|
36
|
+
#info message
|
|
37
|
+
def ilog text="info"
|
|
38
|
+
rofl_logger_check #check if logger is setup
|
|
39
|
+
@logger.info "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
|
|
40
|
+
end
|
|
41
|
+
#debug message
|
|
42
|
+
def dlog text="debug"
|
|
43
|
+
rofl_logger_check #check if logger is setup
|
|
44
|
+
@logger.debug "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
|
|
45
|
+
end
|
|
46
|
+
#get method call trace
|
|
47
|
+
def rofl_meth_trace
|
|
48
|
+
skip = 2 #indicates how many items we skip in the execution stack trace
|
|
49
|
+
call_trace = caller(skip)
|
|
50
|
+
last_meth = call_trace[0][/\`.*?\'/]
|
|
51
|
+
last_meth_name = last_meth.delete("\`").delete("\'") #what was the right string method for this?
|
|
52
|
+
return last_meth_name
|
|
53
|
+
end
|
|
54
|
+
#check if we or an object are ready to rofl
|
|
55
|
+
def rofl? object=self
|
|
56
|
+
has_rofl = (defined? object.rofl?).eql? "method"
|
|
57
|
+
dlog "object of class: #{object.class} is rock'n'rofl." if has_rofl
|
|
58
|
+
return has_rofl
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
#finally we just include ourselves, a little dirty ... what the hell :)
|
|
62
|
+
include Rofl
|
|
63
|
+
#and check, if we're ready to go
|
|
64
|
+
rofl_logger_check
|
data/lib/rofl_trace.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#this module supplies useful trace output for the logger
|
|
2
|
+
module RoflTrace
|
|
3
|
+
#enable vm wide tracing
|
|
4
|
+
def rofl_enable_trace event_regex = /^(call)/
|
|
5
|
+
#this is the Kernel::set_trace_func that we overwrite
|
|
6
|
+
trace_func = Proc.new do |event, file, line, id, binding, classname|
|
|
7
|
+
if event =~ event_regex
|
|
8
|
+
e = {:event=>event,:file=>file,:line=>line,:id=>id,:binding=>binding,:classname=>classname}
|
|
9
|
+
rofl_trace_event_callback e
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
set_trace_func trace_func
|
|
13
|
+
return
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
#disable vm wide tracing
|
|
17
|
+
def rofl_disable_trace
|
|
18
|
+
set_trace_func nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#fires when there is a new trace event
|
|
22
|
+
def rofl_trace_event_callback trace_event
|
|
23
|
+
puts "new trace:"
|
|
24
|
+
trace_event.each { |n,t| puts "#{n}: #{t.inspect}"}
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/test_rofl.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'rofl'
|
|
2
|
+
include Rofl
|
|
3
|
+
|
|
4
|
+
class Test
|
|
5
|
+
def initialize
|
|
6
|
+
dlog "initialize"
|
|
7
|
+
end
|
|
8
|
+
def call_hello_world
|
|
9
|
+
other_method
|
|
10
|
+
hello_world
|
|
11
|
+
other_method
|
|
12
|
+
end
|
|
13
|
+
def hello_world
|
|
14
|
+
other_method
|
|
15
|
+
dlog "hello world!"
|
|
16
|
+
other_method
|
|
17
|
+
end
|
|
18
|
+
def other_method
|
|
19
|
+
puts "puts git other method called"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test = Test.new
|
|
24
|
+
test.call_hello_world
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pangdudu-rofl
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "0.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- pangdudu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-07-17 00:00:00 -07:00
|
|
13
|
+
default_executable: rofl
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: My logger wrapper, includes funkiness.
|
|
17
|
+
email: pangdudu@github
|
|
18
|
+
executables:
|
|
19
|
+
- rofl
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.rdoc
|
|
24
|
+
files:
|
|
25
|
+
- README.rdoc
|
|
26
|
+
- bin/rofl
|
|
27
|
+
- lib/rofl.rb
|
|
28
|
+
- lib/rofl_trace.rb
|
|
29
|
+
- lib/test_rofl.rb
|
|
30
|
+
has_rdoc: true
|
|
31
|
+
homepage: http://github.com/pangdudu/rofl
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: "0"
|
|
42
|
+
version:
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: "0"
|
|
48
|
+
version:
|
|
49
|
+
requirements: []
|
|
50
|
+
|
|
51
|
+
rubyforge_project: rofl
|
|
52
|
+
rubygems_version: 1.2.0
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 2
|
|
55
|
+
summary: rofl! peace.
|
|
56
|
+
test_files: []
|
|
57
|
+
|