vx-lib-logger 0.0.5 → 0.0.6
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/lib/vx/lib/logger.rb +10 -3
- data/lib/vx/lib/logger/handle_exceptions.rb +49 -0
- data/lib/vx/lib/logger/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d75d4c71acfbd5d160ee7383591acea877911cfa
|
4
|
+
data.tar.gz: e72ad9013278de2e4494e59fc39ebdc1a1e58d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db9e744c0eb69e480cf4322134dbb1ea3e9d5c4db761025a2a4cc9daef458ee61a0bfa247755270fe6e42334efeb51f6799ce556553317d0f56af1527cd368fe
|
7
|
+
data.tar.gz: f28c5064bc548ad5cc7a1e5b2006b9e889551fa17f8449fc28d848d95703e4e07b37137e1e72ba2f62856080809d5340707e804d898d9d8aecfde8a9924da664
|
data/lib/vx/lib/logger.rb
CHANGED
@@ -4,13 +4,20 @@ require File.expand_path("../logger/version", __FILE__)
|
|
4
4
|
module Vx ; module Lib
|
5
5
|
module Logger
|
6
6
|
|
7
|
-
autoload :Instance, File.expand_path("../logger/instance",
|
8
|
-
autoload :JsonFormatter, File.expand_path("../logger/json_formatter",
|
9
|
-
autoload :Instrumentations, File.expand_path("../logger/instrumentations",
|
7
|
+
autoload :Instance, File.expand_path("../logger/instance", __FILE__)
|
8
|
+
autoload :JsonFormatter, File.expand_path("../logger/json_formatter", __FILE__)
|
9
|
+
autoload :Instrumentations, File.expand_path("../logger/instrumentations", __FILE__)
|
10
|
+
autoload :HandleExceptions, File.expand_path("../logger/handle_exceptions", __FILE__)
|
11
|
+
|
12
|
+
@@default = Instance.new(STDOUT)
|
10
13
|
|
11
14
|
def self.get(io, options)
|
12
15
|
Instance.new(io, options)
|
13
16
|
end
|
14
17
|
|
18
|
+
def default
|
19
|
+
@@default
|
20
|
+
end
|
21
|
+
|
15
22
|
end
|
16
23
|
end ; end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Vx ; module Lib ; module Logger
|
2
|
+
module Rack
|
3
|
+
|
4
|
+
HandleExceptions = Struct.new(:app) do
|
5
|
+
|
6
|
+
IGNORED_EXCEPTIONS = %w{
|
7
|
+
ActionController::RoutingError
|
8
|
+
}
|
9
|
+
|
10
|
+
def clean_env(env)
|
11
|
+
env = env.select{|k,v| k !~ /^(action_dispatch|puma|session|rack\.session|action_controller)/ }
|
12
|
+
env['HTTP_COOKIE'] &&= env['HTTP_COOKIE'].scan(/.{80}/).join("\n")
|
13
|
+
env
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify(exception, env)
|
17
|
+
unless ignore?(exception)
|
18
|
+
Lib::Logger.default.error(
|
19
|
+
"Unhandled exception",
|
20
|
+
clean_env(env).merge(exception: exception)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
begin
|
27
|
+
response = app.call(env)
|
28
|
+
rescue Exception => ex
|
29
|
+
notify ex, env
|
30
|
+
end
|
31
|
+
|
32
|
+
if ex = framework_exception(env)
|
33
|
+
notify ex, env
|
34
|
+
end
|
35
|
+
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def framework_exception(env)
|
40
|
+
env['rack.exception'] || env['action_dispatch.exception']
|
41
|
+
end
|
42
|
+
|
43
|
+
def ignore?(ex)
|
44
|
+
IGNORED_EXCEPTIONS.include? ex.class.name
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end ; end ; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vx-lib-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/vx/lib/logger.rb
|
68
|
+
- lib/vx/lib/logger/handle_exceptions.rb
|
68
69
|
- lib/vx/lib/logger/instance.rb
|
69
70
|
- lib/vx/lib/logger/instrumentations.rb
|
70
71
|
- lib/vx/lib/logger/json_formatter.rb
|