flume-logger 0.1.0
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/flume-logger.gemspec +24 -0
- data/lib/flume-logger.rb +4 -0
- data/lib/flume-logger/eventserver.rb +42 -0
- data/lib/flume-logger/flume-ng/flume_constants.rb +9 -0
- data/lib/flume-logger/flume-ng/flume_types.rb +37 -0
- data/lib/flume-logger/flume-ng/thrift_source_protocol.rb +138 -0
- data/lib/flume-logger/flume-og/flume_compatibility_constants.rb +9 -0
- data/lib/flume-logger/flume-og/flume_compatibility_types.rb +56 -0
- data/lib/flume-logger/flume-og/thrift_flume_event_server.rb +119 -0
- data/lib/flume-logger/logger.rb +71 -0
- data/lib/flume-logger/version.rb +5 -0
- metadata +121 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lars Sjöström
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# FlumeLogger
|
2
|
+
|
3
|
+
This gem implements a subclass of Ruby's Logger class that logs directly to flume. It writes to a flume agent using thrift RPC, support both FlumeNG (default) or FlumeOG (ThriftLegacy).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'flume-logger'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install flume-logger
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'flume-logger'
|
22
|
+
|
23
|
+
logger = FlumeLogger.new('localhost', 9090)
|
24
|
+
logger.progname = 'test-flume-ng'
|
25
|
+
logger.info "Hello INFO from ruby"
|
26
|
+
logger.warn "Hello WARN from ruby"
|
27
|
+
logger.error "Hello ERROR from ruby"
|
28
|
+
|
29
|
+
og_logger = FlumeLogger.new('localhost', 9090, :og)
|
30
|
+
og_logger.progname = 'test-flume-og'
|
31
|
+
og_logger.info "Hello from ruby"
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flume-logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flume-logger"
|
8
|
+
spec.version = FlumeLogger::VERSION
|
9
|
+
spec.authors = ["Lars Sjöström"]
|
10
|
+
spec.email = ["lars@radicore.se"]
|
11
|
+
spec.description = %q{Ruby logger that writes directly to Flume}
|
12
|
+
spec.summary = %q{Flume logger for ruby}
|
13
|
+
spec.homepage = "https://github.com/lsjostro/ruby-flumelogger"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'thrift', '~> 0.9.1'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/lib/flume-logger.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
class FlumeLogger::Eventserver
|
2
|
+
def initialize(host="localhost", port=9090, flume_type=:ng)
|
3
|
+
@host = host
|
4
|
+
@port = port
|
5
|
+
@client = nil
|
6
|
+
@type = flume_type
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(event)
|
10
|
+
begin
|
11
|
+
connect unless @client
|
12
|
+
|
13
|
+
@client.append(event)
|
14
|
+
rescue => e
|
15
|
+
raise
|
16
|
+
warn "#{self.class} - #{e.class} - #{e.message}: #{event}"
|
17
|
+
close
|
18
|
+
@client = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
@client && @transport.close
|
24
|
+
rescue => e
|
25
|
+
warn "#{self.class} - #{e.class} - #{e.message}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def connect
|
30
|
+
@client = case @type
|
31
|
+
when :ng then
|
32
|
+
@transport = Thrift::FramedTransport.new(Thrift::Socket.new(@host, @port))
|
33
|
+
protocol = Thrift::CompactProtocol.new(@transport)
|
34
|
+
ThriftSourceProtocol::Client.new(protocol)
|
35
|
+
when :og then
|
36
|
+
@transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port))
|
37
|
+
protocol = Thrift::BinaryProtocol.new(@transport)
|
38
|
+
ThriftFlumeEventServer::Client.new(protocol)
|
39
|
+
end
|
40
|
+
@transport.open()
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Status
|
10
|
+
OK = 0
|
11
|
+
FAILED = 1
|
12
|
+
ERROR = 2
|
13
|
+
UNKNOWN = 3
|
14
|
+
VALUE_MAP = {0 => "OK", 1 => "FAILED", 2 => "ERROR", 3 => "UNKNOWN"}
|
15
|
+
VALID_VALUES = Set.new([OK, FAILED, ERROR, UNKNOWN]).freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
class ThriftFlumeEvent
|
19
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
20
|
+
HEADERS = 1
|
21
|
+
BODY = 2
|
22
|
+
|
23
|
+
FIELDS = {
|
24
|
+
HEADERS => {:type => ::Thrift::Types::MAP, :name => 'headers', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}},
|
25
|
+
BODY => {:type => ::Thrift::Types::STRING, :name => 'body', :binary => true}
|
26
|
+
}
|
27
|
+
|
28
|
+
def struct_fields; FIELDS; end
|
29
|
+
|
30
|
+
def validate
|
31
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field headers is unset!') unless @headers
|
32
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field body is unset!') unless @body
|
33
|
+
end
|
34
|
+
|
35
|
+
::Thrift::Struct.generate_accessors self
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'flume_types'
|
9
|
+
|
10
|
+
module ThriftSourceProtocol
|
11
|
+
class Client
|
12
|
+
include ::Thrift::Client
|
13
|
+
|
14
|
+
def append(event)
|
15
|
+
send_append(event)
|
16
|
+
return recv_append()
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_append(event)
|
20
|
+
send_message('append', Append_args, :event => event)
|
21
|
+
end
|
22
|
+
|
23
|
+
def recv_append()
|
24
|
+
result = receive_message(Append_result)
|
25
|
+
return result.success unless result.success.nil?
|
26
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'append failed: unknown result')
|
27
|
+
end
|
28
|
+
|
29
|
+
def appendBatch(events)
|
30
|
+
send_appendBatch(events)
|
31
|
+
return recv_appendBatch()
|
32
|
+
end
|
33
|
+
|
34
|
+
def send_appendBatch(events)
|
35
|
+
send_message('appendBatch', AppendBatch_args, :events => events)
|
36
|
+
end
|
37
|
+
|
38
|
+
def recv_appendBatch()
|
39
|
+
result = receive_message(AppendBatch_result)
|
40
|
+
return result.success unless result.success.nil?
|
41
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'appendBatch failed: unknown result')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class Processor
|
47
|
+
include ::Thrift::Processor
|
48
|
+
|
49
|
+
def process_append(seqid, iprot, oprot)
|
50
|
+
args = read_args(iprot, Append_args)
|
51
|
+
result = Append_result.new()
|
52
|
+
result.success = @handler.append(args.event)
|
53
|
+
write_result(result, oprot, 'append', seqid)
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_appendBatch(seqid, iprot, oprot)
|
57
|
+
args = read_args(iprot, AppendBatch_args)
|
58
|
+
result = AppendBatch_result.new()
|
59
|
+
result.success = @handler.appendBatch(args.events)
|
60
|
+
write_result(result, oprot, 'appendBatch', seqid)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
66
|
+
|
67
|
+
class Append_args
|
68
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
69
|
+
EVENT = 1
|
70
|
+
|
71
|
+
FIELDS = {
|
72
|
+
EVENT => {:type => ::Thrift::Types::STRUCT, :name => 'event', :class => ::ThriftFlumeEvent}
|
73
|
+
}
|
74
|
+
|
75
|
+
def struct_fields; FIELDS; end
|
76
|
+
|
77
|
+
def validate
|
78
|
+
end
|
79
|
+
|
80
|
+
::Thrift::Struct.generate_accessors self
|
81
|
+
end
|
82
|
+
|
83
|
+
class Append_result
|
84
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
85
|
+
SUCCESS = 0
|
86
|
+
|
87
|
+
FIELDS = {
|
88
|
+
SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success', :enum_class => ::Status}
|
89
|
+
}
|
90
|
+
|
91
|
+
def struct_fields; FIELDS; end
|
92
|
+
|
93
|
+
def validate
|
94
|
+
unless @success.nil? || ::Status::VALID_VALUES.include?(@success)
|
95
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field success!')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
::Thrift::Struct.generate_accessors self
|
100
|
+
end
|
101
|
+
|
102
|
+
class AppendBatch_args
|
103
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
104
|
+
EVENTS = 1
|
105
|
+
|
106
|
+
FIELDS = {
|
107
|
+
EVENTS => {:type => ::Thrift::Types::LIST, :name => 'events', :element => {:type => ::Thrift::Types::STRUCT, :class => ::ThriftFlumeEvent}}
|
108
|
+
}
|
109
|
+
|
110
|
+
def struct_fields; FIELDS; end
|
111
|
+
|
112
|
+
def validate
|
113
|
+
end
|
114
|
+
|
115
|
+
::Thrift::Struct.generate_accessors self
|
116
|
+
end
|
117
|
+
|
118
|
+
class AppendBatch_result
|
119
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
120
|
+
SUCCESS = 0
|
121
|
+
|
122
|
+
FIELDS = {
|
123
|
+
SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success', :enum_class => ::Status}
|
124
|
+
}
|
125
|
+
|
126
|
+
def struct_fields; FIELDS; end
|
127
|
+
|
128
|
+
def validate
|
129
|
+
unless @success.nil? || ::Status::VALID_VALUES.include?(@success)
|
130
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field success!')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
::Thrift::Struct.generate_accessors self
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Priority
|
10
|
+
FATAL = 0
|
11
|
+
ERROR = 1
|
12
|
+
WARN = 2
|
13
|
+
INFO = 3
|
14
|
+
DEBUG = 4
|
15
|
+
TRACE = 5
|
16
|
+
VALUE_MAP = {0 => "FATAL", 1 => "ERROR", 2 => "WARN", 3 => "INFO", 4 => "DEBUG", 5 => "TRACE"}
|
17
|
+
VALID_VALUES = Set.new([FATAL, ERROR, WARN, INFO, DEBUG, TRACE]).freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
module EventStatus
|
21
|
+
ACK = 0
|
22
|
+
COMMITED = 1
|
23
|
+
ERR = 2
|
24
|
+
VALUE_MAP = {0 => "ACK", 1 => "COMMITED", 2 => "ERR"}
|
25
|
+
VALID_VALUES = Set.new([ACK, COMMITED, ERR]).freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
class ThriftFlumeEvent
|
29
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
30
|
+
TIMESTAMP = 1
|
31
|
+
PRIORITY = 2
|
32
|
+
BODY = 3
|
33
|
+
NANOS = 4
|
34
|
+
HOST = 5
|
35
|
+
FIELDS = 6
|
36
|
+
|
37
|
+
FIELDS = {
|
38
|
+
TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'},
|
39
|
+
PRIORITY => {:type => ::Thrift::Types::I32, :name => 'priority', :enum_class => ::Priority},
|
40
|
+
BODY => {:type => ::Thrift::Types::STRING, :name => 'body', :binary => true},
|
41
|
+
NANOS => {:type => ::Thrift::Types::I64, :name => 'nanos'},
|
42
|
+
HOST => {:type => ::Thrift::Types::STRING, :name => 'host'},
|
43
|
+
FIELDS => {:type => ::Thrift::Types::MAP, :name => 'fields', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING, :binary => true}}
|
44
|
+
}
|
45
|
+
|
46
|
+
def struct_fields; FIELDS; end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
unless @priority.nil? || ::Priority::VALID_VALUES.include?(@priority)
|
50
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field priority!')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
::Thrift::Struct.generate_accessors self
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'flume_compatibility_types'
|
9
|
+
|
10
|
+
module ThriftFlumeEventServer
|
11
|
+
class Client
|
12
|
+
include ::Thrift::Client
|
13
|
+
|
14
|
+
def append(evt)
|
15
|
+
send_append(evt)
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_append(evt)
|
19
|
+
send_message('append', Append_args, :evt => evt)
|
20
|
+
end
|
21
|
+
def close()
|
22
|
+
send_close()
|
23
|
+
recv_close()
|
24
|
+
end
|
25
|
+
|
26
|
+
def send_close()
|
27
|
+
send_message('close', Close_args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def recv_close()
|
31
|
+
result = receive_message(Close_result)
|
32
|
+
return
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class Processor
|
38
|
+
include ::Thrift::Processor
|
39
|
+
|
40
|
+
def process_append(seqid, iprot, oprot)
|
41
|
+
args = read_args(iprot, Append_args)
|
42
|
+
@handler.append(args.evt)
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_close(seqid, iprot, oprot)
|
47
|
+
args = read_args(iprot, Close_args)
|
48
|
+
result = Close_result.new()
|
49
|
+
@handler.close()
|
50
|
+
write_result(result, oprot, 'close', seqid)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
56
|
+
|
57
|
+
class Append_args
|
58
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
59
|
+
EVT = 1
|
60
|
+
|
61
|
+
FIELDS = {
|
62
|
+
EVT => {:type => ::Thrift::Types::STRUCT, :name => 'evt', :class => ::ThriftFlumeEvent}
|
63
|
+
}
|
64
|
+
|
65
|
+
def struct_fields; FIELDS; end
|
66
|
+
|
67
|
+
def validate
|
68
|
+
end
|
69
|
+
|
70
|
+
::Thrift::Struct.generate_accessors self
|
71
|
+
end
|
72
|
+
|
73
|
+
class Append_result
|
74
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
75
|
+
|
76
|
+
FIELDS = {
|
77
|
+
|
78
|
+
}
|
79
|
+
|
80
|
+
def struct_fields; FIELDS; end
|
81
|
+
|
82
|
+
def validate
|
83
|
+
end
|
84
|
+
|
85
|
+
::Thrift::Struct.generate_accessors self
|
86
|
+
end
|
87
|
+
|
88
|
+
class Close_args
|
89
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
90
|
+
|
91
|
+
FIELDS = {
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
def struct_fields; FIELDS; end
|
96
|
+
|
97
|
+
def validate
|
98
|
+
end
|
99
|
+
|
100
|
+
::Thrift::Struct.generate_accessors self
|
101
|
+
end
|
102
|
+
|
103
|
+
class Close_result
|
104
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
105
|
+
|
106
|
+
FIELDS = {
|
107
|
+
|
108
|
+
}
|
109
|
+
|
110
|
+
def struct_fields; FIELDS; end
|
111
|
+
|
112
|
+
def validate
|
113
|
+
end
|
114
|
+
|
115
|
+
::Thrift::Struct.generate_accessors self
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class FlumeLogger < ::Logger
|
2
|
+
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
HOST = ::Socket.gethostname
|
6
|
+
PRIORITY = { "FATAL" => 0,
|
7
|
+
"CRITICAL" => 0,
|
8
|
+
"ERROR" => 1,
|
9
|
+
"WARNING" => 2,
|
10
|
+
"INFO" => 3,
|
11
|
+
"DEBUG" => 4,
|
12
|
+
"TRACE" => 5 }
|
13
|
+
|
14
|
+
def initialize(host, port, flume_type=:ng, headers={})
|
15
|
+
super(::FlumeLogger::Eventserver.new(host, port, flume_type))
|
16
|
+
@type = flume_type
|
17
|
+
@headers = headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def add(severity, message = nil, progname = nil, &block)
|
21
|
+
severity ||= UNKNOWN
|
22
|
+
if severity < @level
|
23
|
+
return true
|
24
|
+
end
|
25
|
+
progname ||= @progname
|
26
|
+
if message.nil?
|
27
|
+
if block_given?
|
28
|
+
message = yield
|
29
|
+
else
|
30
|
+
message = progname
|
31
|
+
progname = @progname
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@logdev.write(
|
35
|
+
format_message(format_severity(severity), Time.now, progname, message))
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_message(severity, time, progname, message)
|
40
|
+
if progname
|
41
|
+
@headers['application'] = progname
|
42
|
+
end
|
43
|
+
|
44
|
+
event = case @type
|
45
|
+
when :ng
|
46
|
+
$:.push File.expand_path("../flume-ng", __FILE__)
|
47
|
+
require 'thrift_source_protocol'
|
48
|
+
|
49
|
+
@headers['host'] = HOST
|
50
|
+
@headers['pri'] = severity
|
51
|
+
evt = ThriftFlumeEvent.new()
|
52
|
+
evt.headers = @headers
|
53
|
+
evt.body = message
|
54
|
+
evt
|
55
|
+
when :og
|
56
|
+
$:.push File.expand_path("../flume-og", __FILE__)
|
57
|
+
require 'thrift_flume_event_server'
|
58
|
+
|
59
|
+
evt = ThriftFlumeEvent.new()
|
60
|
+
evt.timestamp = time.to_f.to_i * 1000
|
61
|
+
evt.priority = PRIORITY[severity]
|
62
|
+
evt.body = message
|
63
|
+
evt.host = HOST
|
64
|
+
evt.nanos = time.usec * 1000
|
65
|
+
evt.fields = @headers
|
66
|
+
evt
|
67
|
+
end
|
68
|
+
|
69
|
+
event
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flume-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Lars Sj\xC3\xB6str\xC3\xB6m"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-11-11 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thrift
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 9
|
31
|
+
- 1
|
32
|
+
version: 0.9.1
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 3
|
46
|
+
version: "1.3"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Ruby logger that writes directly to Flume
|
63
|
+
email:
|
64
|
+
- lars@radicore.se
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- flume-logger.gemspec
|
78
|
+
- lib/flume-logger.rb
|
79
|
+
- lib/flume-logger/eventserver.rb
|
80
|
+
- lib/flume-logger/flume-ng/flume_constants.rb
|
81
|
+
- lib/flume-logger/flume-ng/flume_types.rb
|
82
|
+
- lib/flume-logger/flume-ng/thrift_source_protocol.rb
|
83
|
+
- lib/flume-logger/flume-og/flume_compatibility_constants.rb
|
84
|
+
- lib/flume-logger/flume-og/flume_compatibility_types.rb
|
85
|
+
- lib/flume-logger/flume-og/thrift_flume_event_server.rb
|
86
|
+
- lib/flume-logger/logger.rb
|
87
|
+
- lib/flume-logger/version.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: https://github.com/lsjostro/ruby-flumelogger
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.3.7.1
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Flume logger for ruby
|
120
|
+
test_files: []
|
121
|
+
|