franz 1.5.4 → 1.5.5
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/franz/logger.rb +24 -46
- data/lib/franz/output.rb +2 -1
- data/lib/franz/tail.rb +5 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 002cdbcf468f836461f433dcac17b46bae72d6d4
|
4
|
+
data.tar.gz: 6d8ff2477e002e1430ea7e5f6123ac0bad96ef27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df6ecca70bdc52d7b6d5e307612a911ded05ecc925a3771be33eff5f9fe4ac6820bcf2550e97c2b4f876ff4219f09f5222174034be7fa197fd4a7c63b2ecd7a
|
7
|
+
data.tar.gz: 067961fe1616a5244781b4ddc248cbcc4a549ea2f183485b79aae6831684b927a27f724f05afb089b3bb977a6bf2975e9e9d65d040a545be88f764bd3ab46196
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.5
|
data/lib/franz/logger.rb
CHANGED
@@ -16,16 +16,16 @@ module Franz
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# A
|
19
|
+
# A colorful JSON logger for Franz.
|
20
20
|
class Logger < Logger
|
21
21
|
# Maps each log level to a unique combination of fore- and background colors
|
22
22
|
SEVERITY_COLORS = {
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
23
|
+
'debug' => [ :blue, :default ],
|
24
|
+
'info' => [ :green, :default ],
|
25
|
+
'warn' => [ :yellow, :default ],
|
26
|
+
'error' => [ :red, :default ],
|
27
|
+
'fatal' => [ :red, :black ],
|
28
|
+
'trace' => [ :magenta, :default ]
|
29
29
|
}
|
30
30
|
|
31
31
|
# Create a new, colorful logger.
|
@@ -44,46 +44,24 @@ module Franz
|
|
44
44
|
|
45
45
|
private
|
46
46
|
def format colorize
|
47
|
-
short_format = "%s\n"
|
48
|
-
long_format = "%s [%s] %s -- %s\n"
|
49
|
-
|
50
47
|
self.formatter = proc do |severity, datetime, _, message|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
File::basename(caller[4]),
|
69
|
-
message
|
70
|
-
]
|
71
|
-
end
|
72
|
-
else # plain
|
73
|
-
if level == 1
|
74
|
-
event = {
|
75
|
-
level: severity.downcase,
|
76
|
-
timestamp: Time.now.iso8601(6)
|
77
|
-
}.merge(message)
|
78
|
-
JSON::generate(event) + "\n"
|
79
|
-
else
|
80
|
-
long_format % [
|
81
|
-
severity,
|
82
|
-
datetime.iso8601(6),
|
83
|
-
File::basename(caller[4]),
|
84
|
-
message
|
85
|
-
]
|
86
|
-
end
|
48
|
+
|
49
|
+
message = { message: message } unless message.is_a? Hash
|
50
|
+
|
51
|
+
event = {
|
52
|
+
severity: severity.downcase!,
|
53
|
+
timestamp: datetime.iso8601(6),
|
54
|
+
marker: File::basename(caller[4])
|
55
|
+
}.merge(message)
|
56
|
+
|
57
|
+
if colorize # console output
|
58
|
+
event = JSON::pretty_generate(event) + "\n"
|
59
|
+
event.colorize \
|
60
|
+
color: SEVERITY_COLORS[severity][0],
|
61
|
+
background: SEVERITY_COLORS[severity][1]
|
62
|
+
|
63
|
+
else # logging to file
|
64
|
+
event = JSON::generate(event) + "\n"
|
87
65
|
end
|
88
66
|
end
|
89
67
|
end
|
data/lib/franz/output.rb
CHANGED
data/lib/franz/tail.rb
CHANGED
@@ -8,7 +8,7 @@ module Franz
|
|
8
8
|
# Tail receives low-level file events from a Watch and handles the actual
|
9
9
|
# reading of files, providing a stream of lines.
|
10
10
|
class Tail
|
11
|
-
|
11
|
+
ERR_BUFFER_FULL = 1
|
12
12
|
ERR_INVALID_EVENT = 2
|
13
13
|
ERR_INCOMPLETE_READ = 3
|
14
14
|
|
@@ -93,42 +93,23 @@ module Franz
|
|
93
93
|
spread: spread
|
94
94
|
end
|
95
95
|
|
96
|
-
nil_reads = 0
|
97
|
-
|
98
96
|
loop do
|
99
97
|
break if @cursors[path] >= size
|
100
98
|
|
101
99
|
begin
|
102
100
|
data = IO::read path, @block_size, @cursors[path]
|
103
101
|
rescue EOFError, Errno::ENOENT
|
104
|
-
|
102
|
+
data = nil
|
105
103
|
end
|
106
104
|
|
107
|
-
|
108
|
-
# the file in question has been rotated. In such a case, we'll
|
109
|
-
# just reset the cursor and bail; hopefully we'll get a
|
110
|
-
# "rotated" event from Watch in the near future.
|
111
|
-
if data.nil?
|
112
|
-
nil_reads += 1
|
113
|
-
|
105
|
+
if data.nil? # Old file went away
|
114
106
|
log.warn \
|
115
107
|
event: 'nil read',
|
116
108
|
path: path,
|
117
109
|
size: size,
|
118
110
|
cursor: @cursors[path],
|
119
111
|
spread: (size - @cursors[path])
|
120
|
-
|
121
|
-
if nil_reads >= 100
|
122
|
-
log.error \
|
123
|
-
event: 'nil read loop',
|
124
|
-
path: path,
|
125
|
-
size: size,
|
126
|
-
cursor: @cursors[path],
|
127
|
-
spread: (size - @cursors[path])
|
128
|
-
@cursors[path] = 0
|
129
|
-
return
|
130
|
-
end
|
131
|
-
|
112
|
+
@cursors[path] = 0
|
132
113
|
next
|
133
114
|
end
|
134
115
|
|
@@ -145,7 +126,7 @@ module Franz
|
|
145
126
|
size: size,
|
146
127
|
cursor: @cursors[path],
|
147
128
|
spread: (size - @cursors[path])
|
148
|
-
exit
|
129
|
+
exit ERR_BUFFER_FULL
|
149
130
|
end
|
150
131
|
|
151
132
|
@cursors[path] += data_size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: franz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Clemmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|