logcast 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/logcast/broadcast.rb +4 -0
- data/lib/logcast/broadcaster.rb +19 -13
- data/lib/logcast/rails.rb +1 -10
- data/lib/logcast.rb +14 -0
- metadata +2 -2
data/lib/logcast/broadcast.rb
CHANGED
data/lib/logcast/broadcaster.rb
CHANGED
@@ -14,8 +14,14 @@ class Logcast::Broadcaster < ::Logger
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def subscribe(subscriber, &block)
|
17
|
+
unless subscriber.respond_to?(:add)
|
18
|
+
original_subscriber = subscriber
|
19
|
+
subscriber = Logger.new(subscriber)
|
20
|
+
subscriber.instance_variable_set(:@logcast_original_subscriber, original_subscriber)
|
21
|
+
end
|
22
|
+
|
17
23
|
if block
|
18
|
-
if
|
24
|
+
if already_subscribed?(subscriber)
|
19
25
|
yield
|
20
26
|
else
|
21
27
|
begin
|
@@ -26,7 +32,7 @@ class Logcast::Broadcaster < ::Logger
|
|
26
32
|
end
|
27
33
|
end
|
28
34
|
else
|
29
|
-
subscribers << subscriber unless
|
35
|
+
subscribers << subscriber unless already_subscribed?(subscriber)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
@@ -37,22 +43,22 @@ class Logcast::Broadcaster < ::Logger
|
|
37
43
|
# Rails 3
|
38
44
|
def add(*args)
|
39
45
|
super
|
40
|
-
|
41
|
-
subscribers.each do |subscriber|
|
42
|
-
subscriber.add(*args)
|
43
|
-
end
|
46
|
+
subscribers.each { |subscriber| subscriber.add(*args) }
|
44
47
|
end
|
45
48
|
|
46
49
|
# Rails 2
|
47
50
|
def write(msg)
|
48
51
|
self << msg
|
52
|
+
subscribers.each { |subscriber| subscriber.add(level, msg.rstrip, progname) }
|
53
|
+
end
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
private
|
56
|
+
|
57
|
+
def already_subscribed?(logger)
|
58
|
+
subscribers.map { |s| log_device(s) }.include?(log_device(logger))
|
59
|
+
end
|
60
|
+
|
61
|
+
def log_device(logger)
|
62
|
+
logger.instance_variable_get(:@logcast_original_subscriber) || logger
|
57
63
|
end
|
58
64
|
end
|
data/lib/logcast/rails.rb
CHANGED
data/lib/logcast.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
module Logcast
|
2
2
|
autoload :Broadcaster, 'logcast/broadcaster.rb'
|
3
3
|
autoload :Broadcast, 'logcast/broadcast.rb'
|
4
|
+
|
5
|
+
def self.engage!
|
6
|
+
logger = if defined?(Rails.logger)
|
7
|
+
Rails.logger
|
8
|
+
elsif defined?(RAILS_DEFAULT_LOGGER)
|
9
|
+
RAILS_DEFAULT_LOGGER
|
10
|
+
else
|
11
|
+
ActiveRecord::Base.logger
|
12
|
+
end
|
13
|
+
|
14
|
+
logger = logger.instance_variable_get(:@logger) if logger.class.name == "ActiveSupport::TaggedLogging"
|
15
|
+
|
16
|
+
logger.extend(Logcast::Broadcast)
|
17
|
+
end
|
4
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|