razing_ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -0
- data/lib/razing_ruby/.DS_Store +0 -0
- data/lib/razing_ruby/exception.rb +2 -0
- data/lib/razing_ruby/logger.rb +76 -0
- data/lib/razing_ruby/version.rb +1 -1
- metadata +2 -1
data/README.md
CHANGED
@@ -18,16 +18,47 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### razing_ruby/kernel
|
22
|
+
|
21
23
|
**Kernel#set_trace_func**
|
22
24
|
|
23
25
|
You can add additional **Kernel#set_trace_func** handlers by running `set_trace_func multiple` times; which will return the index to remove it later with **Kernel#unset_trace_func_index**.
|
24
26
|
|
25
27
|
`set_trace_func` also now accepts a block or a proc argument with the argument taking precendence.
|
26
28
|
|
29
|
+
### razing_ruby/exception (requires kernel automatically)
|
30
|
+
|
27
31
|
**Kernel#set_raise_func**
|
28
32
|
|
29
33
|
You can now add additional **Kernel#raise** handlers! When you use `set_raise_func`; which operates just as `set_trace_func` above; you can now handle exceptions with multiple providers. This is useful if you want to send every exception to Graylog 2 or Airbrake. It also means you will be able to send more exceptions since it integrates directly into Kernel#raise!
|
30
34
|
|
35
|
+
### razing_ruby/logger
|
36
|
+
|
37
|
+
This adds multi logging capabilities. On any Logger object the following methods are avaiable.
|
38
|
+
|
39
|
+
**Logger#add_logger(name[, logger])**
|
40
|
+
|
41
|
+
Adds a logger to this logger to be simoultaneously logged
|
42
|
+
|
43
|
+
- Name: Identifier of the logger or an Logger object (or filename).
|
44
|
+
- Logger: Logger or filename if name is used as an identifier.
|
45
|
+
|
46
|
+
**Logger#del_logger(name)**
|
47
|
+
|
48
|
+
Removes a logger for the additional logger pool
|
49
|
+
|
50
|
+
- Name: Identifier or the Logger object you would like to remove (you can only remove by object if you passed object into the name attribute in add_logger)
|
51
|
+
|
52
|
+
**Logger#get_logger(name)**
|
53
|
+
|
54
|
+
Get a logger by name
|
55
|
+
|
56
|
+
- Name: Identifier or the Logger object you would like to access (you can only access by object if you passed object into the name attribute in add_logger; but why would you?)
|
57
|
+
|
58
|
+
**Logger#get_loggers**
|
59
|
+
|
60
|
+
Return all the registered loggers
|
61
|
+
|
31
62
|
## Contributing
|
32
63
|
|
33
64
|
1. Fork it ( http://github.com/<my-github-username>/razing_ruby/fork )
|
data/lib/razing_ruby/.DS_Store
CHANGED
Binary file
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
attr_reader :logdev
|
5
|
+
|
6
|
+
def add_logger(*a)
|
7
|
+
@logdev.add_logger(*a)
|
8
|
+
end
|
9
|
+
|
10
|
+
def del_logger(*a)
|
11
|
+
@logdev.del_logger(*a)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_logger(*a)
|
15
|
+
@logdev.get_logger(*a)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_loggers
|
19
|
+
@logdev.loggers
|
20
|
+
end
|
21
|
+
|
22
|
+
class LogDevice
|
23
|
+
attr_reader :loggers
|
24
|
+
|
25
|
+
# Create the logger cache
|
26
|
+
def raze_initialize(*a, &b)
|
27
|
+
ruby_initialize(*a, &b)
|
28
|
+
@loggers ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Write a log
|
32
|
+
def raze_write(*a, &b)
|
33
|
+
results = [ruby_write(*a, &b)]
|
34
|
+
@loggers.values.map(&:logdev).reduce(results) do |out, logger|
|
35
|
+
logger.respond_to?(:write) ? out << logger.write(*a, &b) : out
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Add a logger
|
40
|
+
def add_logger(name, logger = nil)
|
41
|
+
name, logger = __prep_logger__(name, logger)
|
42
|
+
return false if logger.logdev == self
|
43
|
+
@loggers[name] = logger
|
44
|
+
end
|
45
|
+
|
46
|
+
# Remove a logger
|
47
|
+
def del_logger(name)
|
48
|
+
@loggers[name].close
|
49
|
+
@loggers.delete(name)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get a logger
|
53
|
+
def get_logger(name)
|
54
|
+
@loggers[name]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Swap the methods with the raze ones
|
58
|
+
alias_method :ruby_initialize, :initialize
|
59
|
+
alias_method :initialize, :raze_initialize
|
60
|
+
alias_method :ruby_write, :write
|
61
|
+
alias_method :write, :raze_write
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# Get the logger for the consumption
|
66
|
+
def __prep_logger__(name, logger = nil)
|
67
|
+
if name.is_a?(String) && ! logger.nil?
|
68
|
+
[name, logger.class <= Logger ? logger : Logger.new(logger)]
|
69
|
+
elsif name.class <= Logger && logger.nil?
|
70
|
+
[name, name]
|
71
|
+
else
|
72
|
+
[name, Logger.new(name)]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/razing_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: razing_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/razing_ruby/.DS_Store
|
62
62
|
- lib/razing_ruby/exception.rb
|
63
63
|
- lib/razing_ruby/kernel.rb
|
64
|
+
- lib/razing_ruby/logger.rb
|
64
65
|
- lib/razing_ruby/version.rb
|
65
66
|
- razing_ruby.gemspec
|
66
67
|
homepage: http://kellybecker.me
|