fluentd 0.10.36 → 0.10.37
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +2 -2
- data/ChangeLog +8 -0
- data/lib/fluent/config.rb +285 -289
- data/lib/fluent/config_dsl.rb +74 -0
- data/lib/fluent/engine.rb +250 -247
- data/lib/fluent/env.rb +5 -5
- data/lib/fluent/event.rb +120 -124
- data/lib/fluent/input.rb +13 -17
- data/lib/fluent/load.rb +1 -0
- data/lib/fluent/log.rb +238 -242
- data/lib/fluent/match.rb +132 -137
- data/lib/fluent/mixin.rb +151 -155
- data/lib/fluent/parser.rb +201 -205
- data/lib/fluent/plugin.rb +117 -121
- data/lib/fluent/plugin/buf_file.rb +8 -0
- data/lib/fluent/plugin/exec_util.rb +49 -0
- data/lib/fluent/plugin/in_exec.rb +44 -30
- data/lib/fluent/plugin/in_forward.rb +4 -2
- data/lib/fluent/plugin/in_http.rb +5 -0
- data/lib/fluent/plugin/in_stream.rb +5 -2
- data/lib/fluent/plugin/out_exec_filter.rb +4 -47
- data/lib/fluent/plugin/out_stdout.rb +21 -1
- data/lib/fluent/process.rb +358 -362
- data/lib/fluent/status.rb +25 -30
- data/lib/fluent/supervisor.rb +277 -281
- data/lib/fluent/test/base.rb +35 -39
- data/lib/fluent/test/input_test.rb +68 -63
- data/lib/fluent/test/output_test.rb +98 -101
- data/lib/fluent/version.rb +1 -1
- data/test/configdsl.rb +77 -0
- data/test/plugin/in_exec.rb +73 -13
- data/test/plugin/in_gc_stat.rb +1 -1
- data/test/plugin/in_object_space.rb +2 -2
- data/test/plugin/out_stdout.rb +45 -2
- data/test/scripts/exec_script.rb +26 -0
- metadata +31 -46
data/lib/fluent/env.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Fluent
|
2
|
-
DEFAULT_CONFIG_PATH = ENV['FLUENT_CONF'] || '/etc/fluent/fluent.conf'
|
3
|
-
DEFAULT_PLUGIN_DIR = ENV['FLUENT_PLUGIN'] || '/etc/fluent/plugin'
|
4
|
-
DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
|
5
|
-
DEFAULT_LISTEN_PORT = 24224
|
6
|
-
DEFAULT_FILE_PERMISSION = 0644
|
2
|
+
DEFAULT_CONFIG_PATH = ENV['FLUENT_CONF'] || '/etc/fluent/fluent.conf'
|
3
|
+
DEFAULT_PLUGIN_DIR = ENV['FLUENT_PLUGIN'] || '/etc/fluent/plugin'
|
4
|
+
DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
|
5
|
+
DEFAULT_LISTEN_PORT = 24224
|
6
|
+
DEFAULT_FILE_PERMISSION = 0644
|
7
7
|
end
|
data/lib/fluent/event.rb
CHANGED
@@ -16,169 +16,165 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
module Fluent
|
19
|
+
class EventStream
|
20
|
+
include Enumerable
|
19
21
|
|
22
|
+
def repeatable?
|
23
|
+
false
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def repeatable?
|
25
|
-
false
|
26
|
-
end
|
27
|
-
|
28
|
-
#def each(&block)
|
29
|
-
#end
|
30
|
-
|
31
|
-
def to_msgpack_stream
|
32
|
-
out = ''
|
33
|
-
each {|time,record|
|
34
|
-
[time,record].to_msgpack(out)
|
35
|
-
}
|
36
|
-
out
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
class OneEventStream < EventStream
|
42
|
-
def initialize(time, record)
|
43
|
-
@time = time
|
44
|
-
@record = record
|
45
|
-
end
|
46
|
-
|
47
|
-
def repeatable?
|
48
|
-
true
|
49
|
-
end
|
50
|
-
|
51
|
-
def each(&block)
|
52
|
-
block.call(@time, @record)
|
53
|
-
nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
class ArrayEventStream < EventStream
|
59
|
-
def initialize(entries)
|
60
|
-
@entries = entries
|
61
|
-
end
|
62
|
-
|
63
|
-
def repeatable?
|
64
|
-
true
|
65
|
-
end
|
66
|
-
|
67
|
-
def empty?
|
68
|
-
@entries.empty?
|
69
|
-
end
|
70
|
-
|
71
|
-
def each(&block)
|
72
|
-
@entries.each(&block)
|
73
|
-
nil
|
74
|
-
end
|
75
|
-
|
76
|
-
#attr_reader :entries
|
77
|
-
#
|
78
|
-
#def to_a
|
79
|
-
# @entries
|
80
|
-
#end
|
81
|
-
end
|
82
|
-
|
26
|
+
#def each(&block)
|
27
|
+
#end
|
83
28
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
29
|
+
def to_msgpack_stream
|
30
|
+
out = ''
|
31
|
+
each {|time,record|
|
32
|
+
[time,record].to_msgpack(out)
|
33
|
+
}
|
34
|
+
out
|
35
|
+
end
|
88
36
|
end
|
89
37
|
|
90
|
-
def add(time, record)
|
91
|
-
@time_array << time
|
92
|
-
@record_array << record
|
93
|
-
end
|
94
38
|
|
95
|
-
|
96
|
-
|
97
|
-
|
39
|
+
class OneEventStream < EventStream
|
40
|
+
def initialize(time, record)
|
41
|
+
@time = time
|
42
|
+
@record = record
|
43
|
+
end
|
98
44
|
|
99
|
-
|
100
|
-
|
101
|
-
|
45
|
+
def repeatable?
|
46
|
+
true
|
47
|
+
end
|
102
48
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
for i in 0..time_array.length-1
|
107
|
-
block.call(time_array[i], record_array[i])
|
49
|
+
def each(&block)
|
50
|
+
block.call(@time, @record)
|
51
|
+
nil
|
108
52
|
end
|
109
|
-
nil
|
110
53
|
end
|
111
|
-
end
|
112
54
|
|
113
|
-
if $use_msgpack_5
|
114
55
|
|
115
|
-
class
|
116
|
-
def initialize(
|
117
|
-
@
|
56
|
+
class ArrayEventStream < EventStream
|
57
|
+
def initialize(entries)
|
58
|
+
@entries = entries
|
118
59
|
end
|
119
60
|
|
120
61
|
def repeatable?
|
121
62
|
true
|
122
63
|
end
|
123
64
|
|
65
|
+
def empty?
|
66
|
+
@entries.empty?
|
67
|
+
end
|
68
|
+
|
124
69
|
def each(&block)
|
125
|
-
|
126
|
-
unpacker = MessagePack::Unpacker.new
|
127
|
-
unpacker.feed_each(@data, &block)
|
70
|
+
@entries.each(&block)
|
128
71
|
nil
|
129
72
|
end
|
130
73
|
|
131
|
-
|
132
|
-
|
133
|
-
|
74
|
+
#attr_reader :entries
|
75
|
+
#
|
76
|
+
#def to_a
|
77
|
+
# @entries
|
78
|
+
#end
|
134
79
|
end
|
135
80
|
|
136
|
-
else # for 0.4.x. Will be removed after 0.5.x is stable
|
137
81
|
|
138
|
-
class
|
139
|
-
def initialize
|
140
|
-
@
|
141
|
-
@
|
82
|
+
class MultiEventStream < EventStream
|
83
|
+
def initialize
|
84
|
+
@time_array = []
|
85
|
+
@record_array = []
|
86
|
+
end
|
87
|
+
|
88
|
+
def add(time, record)
|
89
|
+
@time_array << time
|
90
|
+
@record_array << record
|
142
91
|
end
|
143
92
|
|
144
93
|
def repeatable?
|
145
94
|
true
|
146
95
|
end
|
147
96
|
|
97
|
+
def empty?
|
98
|
+
@time_array.empty?
|
99
|
+
end
|
100
|
+
|
148
101
|
def each(&block)
|
149
|
-
@
|
150
|
-
|
151
|
-
|
102
|
+
time_array = @time_array
|
103
|
+
record_array = @record_array
|
104
|
+
for i in 0..time_array.length-1
|
105
|
+
block.call(time_array[i], record_array[i])
|
106
|
+
end
|
152
107
|
nil
|
153
108
|
end
|
109
|
+
end
|
154
110
|
|
155
|
-
|
156
|
-
|
111
|
+
if $use_msgpack_5
|
112
|
+
|
113
|
+
class MessagePackEventStream < EventStream
|
114
|
+
def initialize(data, cached_unpacker=nil)
|
115
|
+
@data = data
|
116
|
+
end
|
117
|
+
|
118
|
+
def repeatable?
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
def each(&block)
|
123
|
+
# TODO format check
|
124
|
+
unpacker = MessagePack::Unpacker.new
|
125
|
+
unpacker.feed_each(@data, &block)
|
126
|
+
nil
|
127
|
+
end
|
128
|
+
|
129
|
+
def to_msgpack_stream
|
130
|
+
@data
|
131
|
+
end
|
157
132
|
end
|
158
|
-
end
|
159
133
|
|
160
|
-
|
134
|
+
else # for 0.4.x. Will be removed after 0.5.x is stable
|
161
135
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
# end
|
168
|
-
#
|
169
|
-
# def repeatable?
|
170
|
-
# false
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# def each(&block)
|
174
|
-
# return nil if @num == 0
|
175
|
-
# @u.each {|obj|
|
176
|
-
# block.call(obj[0], obj[1])
|
177
|
-
# break if @array.size >= @num
|
178
|
-
# }
|
179
|
-
# end
|
180
|
-
#end
|
136
|
+
class MessagePackEventStream < EventStream
|
137
|
+
def initialize(data, cached_unpacker=nil)
|
138
|
+
@data = data
|
139
|
+
@unpacker = cached_unpacker || MessagePack::Unpacker.new
|
140
|
+
end
|
181
141
|
|
142
|
+
def repeatable?
|
143
|
+
true
|
144
|
+
end
|
182
145
|
|
146
|
+
def each(&block)
|
147
|
+
@unpacker.reset
|
148
|
+
# TODO format check
|
149
|
+
@unpacker.feed_each(@data, &block)
|
150
|
+
nil
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_msgpack_stream
|
154
|
+
@data
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
#class IoEventStream < EventStream
|
161
|
+
# def initialize(io, num)
|
162
|
+
# @io = io
|
163
|
+
# @num = num
|
164
|
+
# @u = MessagePack::Unpacker.new(@io)
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# def repeatable?
|
168
|
+
# false
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# def each(&block)
|
172
|
+
# return nil if @num == 0
|
173
|
+
# @u.each {|obj|
|
174
|
+
# block.call(obj[0], obj[1])
|
175
|
+
# break if @array.size >= @num
|
176
|
+
# }
|
177
|
+
# end
|
178
|
+
#end
|
183
179
|
end
|
184
180
|
|
data/lib/fluent/input.rb
CHANGED
@@ -16,27 +16,23 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
module Fluent
|
19
|
+
class Input
|
20
|
+
include Configurable
|
21
|
+
include PluginId
|
19
22
|
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
def configure(conf)
|
28
|
+
super
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def configure(conf)
|
30
|
-
super
|
31
|
-
end
|
32
|
-
|
33
|
-
def start
|
34
|
-
end
|
31
|
+
def start
|
32
|
+
end
|
35
33
|
|
36
|
-
|
34
|
+
def shutdown
|
35
|
+
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
end
|
42
|
-
|
data/lib/fluent/load.rb
CHANGED
data/lib/fluent/log.rb
CHANGED
@@ -16,281 +16,277 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
module Fluent
|
19
|
+
class Log
|
20
|
+
module TTYColor
|
21
|
+
RESET = "\033]R"
|
22
|
+
CRE = "\033[K"
|
23
|
+
CLEAR = "\033c"
|
24
|
+
NORMAL = "\033[0;39m"
|
25
|
+
RED = "\033[1;31m"
|
26
|
+
GREEN = "\033[1;32m"
|
27
|
+
YELLOW = "\033[1;33m"
|
28
|
+
BLUE = "\033[1;34m"
|
29
|
+
MAGENTA = "\033[1;35m"
|
30
|
+
CYAN = "\033[1;36m"
|
31
|
+
WHITE = "\033[1;37m"
|
32
|
+
end
|
19
33
|
|
34
|
+
LEVEL_TRACE = 0
|
35
|
+
LEVEL_DEBUG = 1
|
36
|
+
LEVEL_INFO = 2
|
37
|
+
LEVEL_WARN = 3
|
38
|
+
LEVEL_ERROR = 4
|
39
|
+
LEVEL_FATAL = 5
|
40
|
+
|
41
|
+
LEVEL_TEXT = %w(trace debug info warn error fatal)
|
42
|
+
|
43
|
+
def initialize(out=STDERR, level=LEVEL_TRACE)
|
44
|
+
@out = out
|
45
|
+
@level = level
|
46
|
+
@debug_mode = false
|
47
|
+
@self_event = false
|
48
|
+
@tag = 'fluent'
|
49
|
+
@time_format = '%Y-%m-%d %H:%M:%S %z '
|
50
|
+
enable_color out.tty?
|
51
|
+
# TODO: This variable name is unclear so we should change to better name.
|
52
|
+
@threads_exclude_events = []
|
53
|
+
end
|
20
54
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
CLEAR = "\033c"
|
26
|
-
NORMAL = "\033[0;39m"
|
27
|
-
RED = "\033[1;31m"
|
28
|
-
GREEN = "\033[1;32m"
|
29
|
-
YELLOW = "\033[1;33m"
|
30
|
-
BLUE = "\033[1;34m"
|
31
|
-
MAGENTA = "\033[1;35m"
|
32
|
-
CYAN = "\033[1;36m"
|
33
|
-
WHITE = "\033[1;37m"
|
34
|
-
end
|
55
|
+
attr_accessor :out
|
56
|
+
attr_accessor :level
|
57
|
+
attr_accessor :tag
|
58
|
+
attr_accessor :time_format
|
35
59
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
LEVEL_ERROR = 4
|
41
|
-
LEVEL_FATAL = 5
|
42
|
-
|
43
|
-
LEVEL_TEXT = %w(trace debug info warn error fatal)
|
44
|
-
|
45
|
-
def initialize(out=STDERR, level=LEVEL_TRACE)
|
46
|
-
@out = out
|
47
|
-
@level = level
|
48
|
-
@debug_mode = false
|
49
|
-
@self_event = false
|
50
|
-
@tag = 'fluent'
|
51
|
-
@time_format = '%Y-%m-%d %H:%M:%S %z '
|
52
|
-
enable_color out.tty?
|
53
|
-
# TODO: This variable name is unclear so we should change to better name.
|
54
|
-
@threads_exclude_events = []
|
55
|
-
end
|
60
|
+
def enable_debug(b=true)
|
61
|
+
@debug_mode = b
|
62
|
+
self
|
63
|
+
end
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
def enable_event(b=true)
|
66
|
+
@self_event = b
|
67
|
+
self
|
68
|
+
end
|
61
69
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
def enable_color(b=true)
|
71
|
+
if b
|
72
|
+
@color_trace = TTYColor::BLUE
|
73
|
+
@color_debug = TTYColor::WHITE
|
74
|
+
@color_info = TTYColor::GREEN
|
75
|
+
@color_warn = TTYColor::YELLOW
|
76
|
+
@color_error = TTYColor::MAGENTA
|
77
|
+
@color_fatal = TTYColor::RED
|
78
|
+
@color_reset = TTYColor::NORMAL
|
79
|
+
else
|
80
|
+
@color_trace = ''
|
81
|
+
@color_debug = ''
|
82
|
+
@color_info = ''
|
83
|
+
@color_warn = ''
|
84
|
+
@color_error = ''
|
85
|
+
@color_fatal = ''
|
86
|
+
@color_reset = ''
|
87
|
+
end
|
88
|
+
self
|
89
|
+
end
|
66
90
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
91
|
+
# If you want to suppress event emitting in specific thread, please use this method.
|
92
|
+
# Events in passed thread are never emitted.
|
93
|
+
def disable_events(thread)
|
94
|
+
@threads_exclude_events.push(thread) unless @threads_exclude_events.include?(thread)
|
95
|
+
end
|
71
96
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@color_debug = TTYColor::WHITE
|
76
|
-
@color_info = TTYColor::GREEN
|
77
|
-
@color_warn = TTYColor::YELLOW
|
78
|
-
@color_error = TTYColor::MAGENTA
|
79
|
-
@color_fatal = TTYColor::RED
|
80
|
-
@color_reset = TTYColor::NORMAL
|
81
|
-
else
|
82
|
-
@color_trace = ''
|
83
|
-
@color_debug = ''
|
84
|
-
@color_info = ''
|
85
|
-
@color_warn = ''
|
86
|
-
@color_error = ''
|
87
|
-
@color_fatal = ''
|
88
|
-
@color_reset = ''
|
97
|
+
def on_trace(&block)
|
98
|
+
return if @level > LEVEL_TRACE
|
99
|
+
block.call if block
|
89
100
|
end
|
90
|
-
self
|
91
|
-
end
|
92
101
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
102
|
+
def trace(*args, &block)
|
103
|
+
return if @level > LEVEL_TRACE
|
104
|
+
args << block.call if block
|
105
|
+
time, msg = event(:trace, args)
|
106
|
+
puts [@color_trace, caller_line(time, 1, LEVEL_TRACE), msg, @color_reset].join
|
107
|
+
end
|
108
|
+
alias TRACE trace
|
98
109
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
110
|
+
def trace_backtrace(backtrace=$!.backtrace)
|
111
|
+
return if @level > LEVEL_TRACE
|
112
|
+
time = Time.now
|
113
|
+
backtrace.each {|msg|
|
114
|
+
puts [" ", caller_line(time, 4, LEVEL_TRACE), msg].join
|
115
|
+
}
|
116
|
+
nil
|
117
|
+
end
|
103
118
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
puts [@color_trace, caller_line(time, 1, LEVEL_TRACE), msg, @color_reset].join
|
109
|
-
end
|
110
|
-
alias TRACE trace
|
111
|
-
|
112
|
-
def trace_backtrace(backtrace=$!.backtrace)
|
113
|
-
return if @level > LEVEL_TRACE
|
114
|
-
time = Time.now
|
115
|
-
backtrace.each {|msg|
|
116
|
-
puts [" ", caller_line(time, 4, LEVEL_TRACE), msg].join
|
117
|
-
}
|
118
|
-
nil
|
119
|
-
end
|
119
|
+
def on_debug(&block)
|
120
|
+
return if @level > LEVEL_DEBUG
|
121
|
+
block.call if block
|
122
|
+
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
def debug(*args, &block)
|
125
|
+
return if @level > LEVEL_DEBUG
|
126
|
+
args << block.call if block
|
127
|
+
time, msg = event(:debug, args)
|
128
|
+
puts [@color_debug, caller_line(time, 1, LEVEL_DEBUG), msg, @color_reset].join
|
129
|
+
end
|
130
|
+
alias DEBUG debug
|
125
131
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
def debug_backtrace(backtrace=$!.backtrace)
|
135
|
-
return if @level > LEVEL_DEBUG
|
136
|
-
time = Time.now
|
137
|
-
backtrace.each {|msg|
|
138
|
-
puts [" ", caller_line(time, 4, LEVEL_DEBUG), msg].join
|
139
|
-
}
|
140
|
-
nil
|
141
|
-
end
|
132
|
+
def debug_backtrace(backtrace=$!.backtrace)
|
133
|
+
return if @level > LEVEL_DEBUG
|
134
|
+
time = Time.now
|
135
|
+
backtrace.each {|msg|
|
136
|
+
puts [" ", caller_line(time, 4, LEVEL_DEBUG), msg].join
|
137
|
+
}
|
138
|
+
nil
|
139
|
+
end
|
142
140
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
def on_info(&block)
|
142
|
+
return if @level > LEVEL_INFO
|
143
|
+
block.call if block
|
144
|
+
end
|
147
145
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
def info_backtrace(backtrace=$!.backtrace)
|
157
|
-
return if @level > LEVEL_INFO
|
158
|
-
time = Time.now
|
159
|
-
backtrace.each {|msg|
|
160
|
-
puts [" ", caller_line(time, 4, LEVEL_INFO), msg].join
|
161
|
-
}
|
162
|
-
nil
|
163
|
-
end
|
146
|
+
def info(*args, &block)
|
147
|
+
return if @level > LEVEL_INFO
|
148
|
+
args << block.call if block
|
149
|
+
time, msg = event(:info, args)
|
150
|
+
puts [@color_info, caller_line(time, 1, LEVEL_INFO), msg, @color_reset].join
|
151
|
+
end
|
152
|
+
alias INFO info
|
164
153
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
154
|
+
def info_backtrace(backtrace=$!.backtrace)
|
155
|
+
return if @level > LEVEL_INFO
|
156
|
+
time = Time.now
|
157
|
+
backtrace.each {|msg|
|
158
|
+
puts [" ", caller_line(time, 4, LEVEL_INFO), msg].join
|
159
|
+
}
|
160
|
+
nil
|
161
|
+
end
|
169
162
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
puts [@color_warn, caller_line(time, 1, LEVEL_WARN), msg, @color_reset].join
|
175
|
-
end
|
176
|
-
alias WARN warn
|
177
|
-
|
178
|
-
def warn_backtrace(backtrace=$!.backtrace)
|
179
|
-
return if @level > LEVEL_WARN
|
180
|
-
time = Time.now
|
181
|
-
backtrace.each {|msg|
|
182
|
-
puts [" ", caller_line(time, 4, LEVEL_WARN), msg].join
|
183
|
-
}
|
184
|
-
nil
|
185
|
-
end
|
163
|
+
def on_warn(&block)
|
164
|
+
return if @level > LEVEL_WARN
|
165
|
+
block.call if block
|
166
|
+
end
|
186
167
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
168
|
+
def warn(*args, &block)
|
169
|
+
return if @level > LEVEL_WARN
|
170
|
+
args << block.call if block
|
171
|
+
time, msg = event(:warn, args)
|
172
|
+
puts [@color_warn, caller_line(time, 1, LEVEL_WARN), msg, @color_reset].join
|
173
|
+
end
|
174
|
+
alias WARN warn
|
191
175
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
def error_backtrace(backtrace=$!.backtrace)
|
201
|
-
return if @level > LEVEL_ERROR
|
202
|
-
time = Time.now
|
203
|
-
backtrace.each {|msg|
|
204
|
-
puts [" ", caller_line(time, 4, LEVEL_ERROR), msg].join
|
205
|
-
}
|
206
|
-
nil
|
207
|
-
end
|
176
|
+
def warn_backtrace(backtrace=$!.backtrace)
|
177
|
+
return if @level > LEVEL_WARN
|
178
|
+
time = Time.now
|
179
|
+
backtrace.each {|msg|
|
180
|
+
puts [" ", caller_line(time, 4, LEVEL_WARN), msg].join
|
181
|
+
}
|
182
|
+
nil
|
183
|
+
end
|
208
184
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
185
|
+
def on_error(&block)
|
186
|
+
return if @level > LEVEL_ERROR
|
187
|
+
block.call if block
|
188
|
+
end
|
213
189
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
def fatal_backtrace(backtrace=$!.backtrace)
|
223
|
-
return if @level > LEVEL_FATAL
|
224
|
-
time = Time.now
|
225
|
-
backtrace.each {|msg|
|
226
|
-
puts [" ", caller_line(time, 4, LEVEL_FATAL), msg].join
|
227
|
-
}
|
228
|
-
nil
|
229
|
-
end
|
190
|
+
def error(*args, &block)
|
191
|
+
return if @level > LEVEL_ERROR
|
192
|
+
args << block.call if block
|
193
|
+
time, msg = event(:error, args)
|
194
|
+
puts [@color_error, caller_line(time, 1, LEVEL_ERROR), msg, @color_reset].join
|
195
|
+
end
|
196
|
+
alias ERROR error
|
230
197
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
198
|
+
def error_backtrace(backtrace=$!.backtrace)
|
199
|
+
return if @level > LEVEL_ERROR
|
200
|
+
time = Time.now
|
201
|
+
backtrace.each {|msg|
|
202
|
+
puts [" ", caller_line(time, 4, LEVEL_ERROR), msg].join
|
203
|
+
}
|
204
|
+
nil
|
205
|
+
end
|
239
206
|
|
240
|
-
|
241
|
-
|
242
|
-
|
207
|
+
def on_fatal(&block)
|
208
|
+
return if @level > LEVEL_FATAL
|
209
|
+
block.call if block
|
210
|
+
end
|
243
211
|
|
244
|
-
|
245
|
-
|
246
|
-
|
212
|
+
def fatal(*args, &block)
|
213
|
+
return if @level > LEVEL_FATAL
|
214
|
+
args << block.call if block
|
215
|
+
time, msg = event(:fatal, args)
|
216
|
+
puts [@color_fatal, caller_line(time, 1, LEVEL_FATAL), msg, @color_reset].join
|
217
|
+
end
|
218
|
+
alias FATAL fatal
|
247
219
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
220
|
+
def fatal_backtrace(backtrace=$!.backtrace)
|
221
|
+
return if @level > LEVEL_FATAL
|
222
|
+
time = Time.now
|
223
|
+
backtrace.each {|msg|
|
224
|
+
puts [" ", caller_line(time, 4, LEVEL_FATAL), msg].join
|
225
|
+
}
|
226
|
+
nil
|
227
|
+
end
|
228
|
+
|
229
|
+
def puts(msg)
|
230
|
+
@out.puts(msg)
|
231
|
+
@out.flush
|
232
|
+
msg
|
233
|
+
rescue
|
234
|
+
# FIXME
|
235
|
+
nil
|
236
|
+
end
|
237
|
+
|
238
|
+
def write(data)
|
239
|
+
@out.write(data)
|
240
|
+
end
|
241
|
+
|
242
|
+
def flush
|
243
|
+
@out.flush
|
244
|
+
end
|
245
|
+
|
246
|
+
private
|
247
|
+
def event(level, args)
|
248
|
+
time = Time.now
|
249
|
+
message = ''
|
250
|
+
map = {}
|
251
|
+
args.each {|a|
|
252
|
+
if a.is_a?(Hash)
|
253
|
+
a.each_pair {|k,v|
|
254
|
+
map[k.to_s] = v
|
255
|
+
}
|
256
|
+
else
|
257
|
+
message << a.to_s
|
258
|
+
end
|
259
|
+
}
|
260
|
+
|
261
|
+
unless @threads_exclude_events.include?(Thread.current)
|
262
|
+
record = map.dup
|
263
|
+
record.keys.each {|key|
|
264
|
+
record[key] = record[key].inspect unless record[key].respond_to?(:to_msgpack)
|
257
265
|
}
|
258
|
-
|
259
|
-
|
266
|
+
record['message'] = message.dup
|
267
|
+
Engine.push_log_event("#{@tag}.#{level}", time.to_i, record)
|
260
268
|
end
|
261
|
-
}
|
262
269
|
|
263
|
-
|
264
|
-
|
265
|
-
record.keys.each {|key|
|
266
|
-
record[key] = record[key].inspect unless record[key].respond_to?(:to_msgpack)
|
270
|
+
map.each_pair {|k,v|
|
271
|
+
message << " #{k}=#{v.inspect}"
|
267
272
|
}
|
268
|
-
record['message'] = message.dup
|
269
|
-
Engine.push_log_event("#{@tag}.#{level}", time.to_i, record)
|
270
|
-
end
|
271
273
|
|
272
|
-
|
273
|
-
|
274
|
-
}
|
275
|
-
|
276
|
-
return time, message
|
277
|
-
end
|
274
|
+
return time, message
|
275
|
+
end
|
278
276
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
277
|
+
def caller_line(time, depth, level)
|
278
|
+
line = caller(depth+1)[0]
|
279
|
+
log_msg = "#{time.strftime(@time_format)}[#{LEVEL_TEXT[level]}]: "
|
280
|
+
if @debug_mode
|
281
|
+
if match = /^(.+?):(\d+)(?::in `(.*)')?/.match(line)
|
282
|
+
file = match[1].split('/')[-2,2].join('/')
|
283
|
+
line = match[2]
|
284
|
+
method = match[3]
|
285
|
+
return "#{log_msg}#{file}:#{line}:#{method}: "
|
286
|
+
end
|
288
287
|
end
|
288
|
+
return log_msg
|
289
289
|
end
|
290
|
-
return log_msg
|
291
290
|
end
|
292
291
|
end
|
293
292
|
|
294
|
-
|
295
|
-
end
|
296
|
-
|