huyegger 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -3
- data/huyegger.gemspec +4 -4
- data/lib/huyegger/formatter.rb +13 -13
- data/lib/huyegger/middleware.rb +13 -0
- data/lib/huyegger/railtie.rb +21 -0
- data/lib/huyegger/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8bd450e48cb0daa896999b9634abd56da369cd
|
4
|
+
data.tar.gz: 4e57c71f1cb6a65ebf762c7cde25d6b64eb069c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026347763efcb7c2a06b6c469dfed84b757c97def2ad30182d27e9b379fb0ca3b5375bb7ed9cee1902a43b3416db45aaf8bbf2c4f10ee1c4c49a41352e25f7a4
|
7
|
+
data.tar.gz: 2fc8dad76f40c84d4c8dbcca9d030b1b61e434b62207e390ca617884414df641c302e12815c9b870846a803542ae1574b22e9a06cceee6e3735323288f204f19
|
data/README.md
CHANGED
@@ -26,12 +26,12 @@ logger = Huyegger::Logger.new(syslog_logger)
|
|
26
26
|
# Write messages:
|
27
27
|
logger.info "log message"
|
28
28
|
# => { "level": "INFO", "message": "test" }
|
29
|
-
logger.info { "http.host" =>
|
29
|
+
logger.info { "http.host" => "127.0.0.1", message: "log message" }
|
30
30
|
# => { "level": "INFO", "message": "test", "http.host": "127.0.0.1" }
|
31
31
|
|
32
32
|
# Store context for all log messages, it will be merged to resulting messages
|
33
|
-
logger.context("http.host" =>
|
34
|
-
logger.info(
|
33
|
+
logger.context("http.host" => "127.0.0.1")
|
34
|
+
logger.info("test")
|
35
35
|
# => { "level": "INFO", "message": "test", "http.host": "127.0.0.1" }
|
36
36
|
|
37
37
|
# Remove context
|
@@ -44,6 +44,29 @@ Huyegger.json_encoder = proc { |obj, *opts| Oj.dump(obj, *opts) }
|
|
44
44
|
# but you need to `require "json"` to use default json encoder.
|
45
45
|
```
|
46
46
|
|
47
|
+
To use with Rails
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# inside config/enviroments/production.rb
|
51
|
+
require "huyegger/railtie"
|
52
|
+
|
53
|
+
# inside app/controller/application_controller.rb
|
54
|
+
class ApplicationController < ActionController::Base
|
55
|
+
before_action :set_context
|
56
|
+
|
57
|
+
...
|
58
|
+
|
59
|
+
def set_context
|
60
|
+
Rails.logger.context(
|
61
|
+
"http.host" => request.host,
|
62
|
+
"http.method" => request.request_method,
|
63
|
+
"http.path" => request.path,
|
64
|
+
"http.addr" => request.remote_ip
|
65
|
+
) if Rails.logger.respond_to?(:context)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
47
70
|
## Contributing
|
48
71
|
|
49
72
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mainameiz/huyegger.
|
data/huyegger.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "huyegger/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "huyegger"
|
@@ -13,10 +13,10 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://github.com/mainameiz/huyegger"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
17
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
18
|
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata[
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
20
|
else
|
21
21
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
22
|
"public gem pushes."
|
data/lib/huyegger/formatter.rb
CHANGED
@@ -4,12 +4,12 @@ require "logger"
|
|
4
4
|
module Huyegger
|
5
5
|
class Formatter
|
6
6
|
SEVERITY_STR = {
|
7
|
-
::Logger::DEBUG =>
|
8
|
-
::Logger::INFO =>
|
9
|
-
::Logger::WARN =>
|
10
|
-
::Logger::ERROR =>
|
11
|
-
::Logger::FATAL =>
|
12
|
-
::Logger::UNKNOWN =>
|
7
|
+
::Logger::DEBUG => "DEBUG",
|
8
|
+
::Logger::INFO => "INFO",
|
9
|
+
::Logger::WARN => "WARN",
|
10
|
+
::Logger::ERROR => "ERROR",
|
11
|
+
::Logger::FATAL => "FATAL",
|
12
|
+
::Logger::UNKNOWN => "UNKNOWN"
|
13
13
|
}
|
14
14
|
|
15
15
|
attr_reader :original_formatter
|
@@ -35,7 +35,7 @@ module Huyegger
|
|
35
35
|
json_message.merge!(__context__)
|
36
36
|
add_message!(json_message, msg)
|
37
37
|
|
38
|
-
Huyegger.json_encoder.call(json_message)
|
38
|
+
"#{Huyegger.json_encoder.call(json_message)}\n"
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -43,23 +43,23 @@ module Huyegger
|
|
43
43
|
def add_severity!(json_message, severity)
|
44
44
|
case severity
|
45
45
|
when String
|
46
|
-
json_message.merge!(
|
46
|
+
json_message.merge!("level" => severity)
|
47
47
|
when Integer
|
48
|
-
json_message.merge!(
|
48
|
+
json_message.merge!("level" => SEVERITY_STR.fetch(severity))
|
49
49
|
else
|
50
|
-
json_message.merge!(
|
50
|
+
json_message.merge!("level" => SEVERITY_STR.fetch(::Logger::UNKNOWN))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def add_message!(json_message, msg)
|
55
55
|
case msg
|
56
56
|
when String
|
57
|
-
json_message.merge!(
|
57
|
+
json_message.merge!("message" => msg)
|
58
58
|
when Hash
|
59
|
-
json_message.merge!(
|
59
|
+
json_message.merge!("message" => "Empty message") # default message because it is required
|
60
60
|
json_message.merge!(msg)
|
61
61
|
else
|
62
|
-
json_message.merge!(
|
62
|
+
json_message.merge!("message" => msg.inspect)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Huyegger
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "huyegger.insert_middleware" do |app|
|
4
|
+
if ActionDispatch.const_defined? :RequestId
|
5
|
+
app.config.middleware.insert_after ActionDispatch::RequestId, Huyegger::Middleware
|
6
|
+
else
|
7
|
+
app.config.middleware.insert_after Rack::MethodOverride, Huyegger::Middleware
|
8
|
+
end
|
9
|
+
|
10
|
+
if ActiveSupport.const_defined?(:Reloader) && ActiveSupport::Reloader.respond_to?(:to_complete)
|
11
|
+
ActiveSupport::Reloader.to_complete do
|
12
|
+
Rails.logger.purge_context! if Rails.logger.is_a?(Huyegger::Logger)
|
13
|
+
end
|
14
|
+
elsif ActionDispatch.const_defined?(:Reloader) && ActionDispatch::Reloader.respond_to?(:to_cleanup)
|
15
|
+
ActionDispatch::Reloader.to_cleanup do
|
16
|
+
Rails.logger.purge_context! if Rails.logger.is_a?(Huyegger::Logger)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/huyegger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huyegger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikolay Markov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- lib/huyegger.rb
|
71
71
|
- lib/huyegger/formatter.rb
|
72
72
|
- lib/huyegger/logger.rb
|
73
|
+
- lib/huyegger/middleware.rb
|
74
|
+
- lib/huyegger/railtie.rb
|
73
75
|
- lib/huyegger/version.rb
|
74
76
|
homepage: http://github.com/mainameiz/huyegger
|
75
77
|
licenses:
|