wildcloud-logger 0.0.2 → 0.0.3
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/CHANGELOG.md
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright 2011 Marek Jelen
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'thread'
|
16
|
+
|
17
|
+
module Wildcloud
|
18
|
+
module Logger
|
19
|
+
module Middleware
|
20
|
+
class File
|
21
|
+
|
22
|
+
def initialize(app, options = {})
|
23
|
+
@options = options
|
24
|
+
@options[:io].sync = true
|
25
|
+
@queue = Queue.new
|
26
|
+
@app = app
|
27
|
+
@thread = Thread.new do
|
28
|
+
loop do
|
29
|
+
begin
|
30
|
+
msg = @queue.pop
|
31
|
+
if @options[:key]
|
32
|
+
log = msg[@options[:key]]
|
33
|
+
else
|
34
|
+
log = msg[:level].to_s
|
35
|
+
log << " (#{Time.at(msg[:timestamp])})"
|
36
|
+
log << " :"
|
37
|
+
log << " #{msg[:application]}" if msg[:application]
|
38
|
+
log << " :"
|
39
|
+
log << " #{msg[:component]}" if msg[:component]
|
40
|
+
log << " :"
|
41
|
+
log << " #{msg[:message]}"
|
42
|
+
end
|
43
|
+
@options[:io].puts(log)
|
44
|
+
rescue Exception => e
|
45
|
+
puts e.message
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def call(msg)
|
52
|
+
@queue << msg
|
53
|
+
@app.call(msg)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright 2011 Marek Jelen
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'socket'
|
16
|
+
require 'thread'
|
17
|
+
|
18
|
+
module Wildcloud
|
19
|
+
module Logger
|
20
|
+
module Middleware
|
21
|
+
class Logeen
|
22
|
+
|
23
|
+
class Connection < EventMachine::Connection
|
24
|
+
|
25
|
+
def initialize(logger)
|
26
|
+
super
|
27
|
+
@logger = logger
|
28
|
+
end
|
29
|
+
|
30
|
+
def unbind
|
31
|
+
@logger.reconnect
|
32
|
+
@logger = nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def reconnect
|
37
|
+
@socket = EventMachine.connect(@options[:address], @options[:port], Connection, self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(app, options = {})
|
41
|
+
@options = options
|
42
|
+
@queue = Queue.new
|
43
|
+
@app = app
|
44
|
+
reconnect
|
45
|
+
@thread = Thread.new do
|
46
|
+
loop do
|
47
|
+
msg = @queue.pop.to_s
|
48
|
+
msg = "#{msg.size}\n0#{msg}"
|
49
|
+
@socket.send_data(msg)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def call(msg)
|
55
|
+
@queue << msg[:json_encoded]
|
56
|
+
@app.call(msg)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wildcloud-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple logging library inspired by Rack architecture
|
15
15
|
email:
|
@@ -21,7 +21,9 @@ files:
|
|
21
21
|
- lib/wildcloud/logger/logger.rb
|
22
22
|
- lib/wildcloud/logger/middleware/amqp.rb
|
23
23
|
- lib/wildcloud/logger/middleware/console.rb
|
24
|
+
- lib/wildcloud/logger/middleware/file.rb
|
24
25
|
- lib/wildcloud/logger/middleware/json.rb
|
26
|
+
- lib/wildcloud/logger/middleware/logeen.rb
|
25
27
|
- lib/wildcloud/logger/version.rb
|
26
28
|
- lib/wildcloud/logger.rb
|
27
29
|
- LICENSE
|