releaseable 0.0.14 → 0.0.15
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/VERSION +1 -1
- data/lib/releaseable/extensions.rb +66 -39
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.15
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'logglier'
|
3
3
|
require 'stringio'
|
4
|
+
require 'timeout'
|
4
5
|
require 'java'
|
5
6
|
|
6
7
|
# Selectively silence verbose JRuby warnings
|
@@ -43,23 +44,34 @@ class Logger
|
|
43
44
|
self.class.sound_alarm beeps
|
44
45
|
end
|
45
46
|
|
47
|
+
# Execute with timeout and protection from exceptions
|
48
|
+
def with_timeout out=5
|
49
|
+
Timeout::timeout(out) { yield }
|
50
|
+
rescue => e
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
46
54
|
# Trace errors in json format
|
47
55
|
def trace error
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
hash
|
56
|
+
if handler
|
57
|
+
with_timeout do
|
58
|
+
hash = error.is_a?(Hash) ? error : {:msg => error}
|
59
|
+
handler.add(hash[:severity] || Logger::UNKNOWN) do
|
60
|
+
hash.merge :tag => @config[:tag]
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
56
66
|
# Finalize logger
|
57
67
|
def finalize
|
58
|
-
if
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
if handler
|
69
|
+
with_timeout do
|
70
|
+
trace :failsafe => @config[:failsafe].string if @config[:failsafe].respond_to? :string
|
71
|
+
sound_alarm
|
72
|
+
sleep 2
|
73
|
+
handler.logdev.dev.deliverer.kill
|
74
|
+
end
|
63
75
|
end
|
64
76
|
close
|
65
77
|
end
|
@@ -67,51 +79,66 @@ class Logger
|
|
67
79
|
alias old_fatal fatal
|
68
80
|
|
69
81
|
def fatal *args
|
70
|
-
if
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
if handler
|
83
|
+
with_timeout do
|
84
|
+
entry = args.first
|
85
|
+
case entry
|
86
|
+
when Exception
|
87
|
+
trace :severity => Logger::FATAL,
|
88
|
+
:error => entry.class,
|
89
|
+
:msg => entry.message,
|
90
|
+
:backtrace => (entry.backtrace || []).join(', ')
|
91
|
+
else
|
92
|
+
trace :severity => Logger::INFO, :msg => "#{args.join(', ')}"
|
93
|
+
old_fatal *args
|
94
|
+
end
|
81
95
|
end
|
82
96
|
else
|
83
97
|
old_fatal *args
|
84
98
|
end
|
85
99
|
end
|
86
100
|
|
87
|
-
# Extended
|
101
|
+
# Extended handler for fatal errors
|
102
|
+
def handler
|
103
|
+
return @handler if @handler
|
104
|
+
|
105
|
+
if @handle_fatal_errors
|
106
|
+
with_timeout do
|
107
|
+
# Something that should be interrupted if it takes too much time...
|
108
|
+
@handler = Logglier.new "#{@config[:domain]}/inputs/#{@config[:input]}",
|
109
|
+
:failsafe => @config[:failsafe],
|
110
|
+
:read_timeout => 10, # defaults to 120
|
111
|
+
:open_timeout => 10, # defaults to 120
|
112
|
+
:threaded => true,
|
113
|
+
:format => :json
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Extended configuration for Logger
|
88
119
|
def configure config={}, &formatter
|
89
120
|
@config = (config[:log] || config).dup
|
90
121
|
@config[:beeps] ||= 0
|
91
|
-
@config[:time_format] ||= @config[:time] || '%M:%S.%N'
|
122
|
+
@config[:time_format] ||= @config[:time] || '%H:%M:%S.%N'
|
123
|
+
|
124
|
+
@handle_fatal_errors = @config[:ignore] ? false : true
|
125
|
+
|
126
|
+
if @handle_fatal_errors
|
92
127
|
|
93
|
-
unless @config[:ignore] # fatal errors
|
94
128
|
@config[:tag] = config[:tag] || config[:name] || !config[:connection] ? "Tag#{rand(10000)}" :
|
95
129
|
"#{config[:env]}-#{config[:connection][:client_id]}-#{config[:connection][:account]}"
|
96
|
-
|
97
|
-
when Symbol
|
98
|
-
INPUTS[@config[:input]]
|
99
|
-
when nil
|
100
|
-
INPUTS[:opts]
|
101
|
-
else
|
102
|
-
@config[:input]
|
103
|
-
end
|
104
|
-
domain ||= @config[:domain] || 'https://logs.loggly.com'
|
130
|
+
@config[:domain] ||= 'https://logs.loggly.com'
|
105
131
|
@config[:failsafe] ||= StringIO.new("") # $stderr
|
106
132
|
|
107
|
-
@
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
133
|
+
@config[:input] = case @config[:input]
|
134
|
+
when Symbol
|
135
|
+
INPUTS[@config[:input]]
|
136
|
+
when nil
|
137
|
+
INPUTS[:opts]
|
138
|
+
else
|
139
|
+
@config[:input]
|
140
|
+
end
|
113
141
|
end
|
114
|
-
|
115
142
|
self.level = @config[:level] || Logger::INFO
|
116
143
|
self.formatter = formatter || proc do |level, time, prog, msg|
|
117
144
|
"#{time.strftime(@config[:time_format])} #{msg}\n"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: releaseable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.15
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- arvicco
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|