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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3f517dd1fe0509a84de820331fb05e09ca43804
4
- data.tar.gz: 85a02b0da52849d8f842b6e89dd1bf8628ae2047
3
+ metadata.gz: 8b8bd450e48cb0daa896999b9634abd56da369cd
4
+ data.tar.gz: 4e57c71f1cb6a65ebf762c7cde25d6b64eb069c3
5
5
  SHA512:
6
- metadata.gz: 4c89fa43abedefb10c0250bb09a106cb174d027a9999cc4072496002a82647580c23904cdfffa07e4de17262aac1e88463c426332ea386c3d219d0a80c1ea944
7
- data.tar.gz: d60edbc668718cce40af61582a83621c18918e6168aaad64fca1a8ed744949bfd5cd274d50d52372846445ca8f5b10b2968fec11ae411c39e50698319045f6ca
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" => '127.0.0.1', message: "log message" }
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" => '127.0.0.1')
34
- logger.info('test')
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('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'huyegger/version'
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 'allowed_push_host'
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['allowed_push_host'] = "https://rubygems.org"
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."
@@ -4,12 +4,12 @@ require "logger"
4
4
  module Huyegger
5
5
  class Formatter
6
6
  SEVERITY_STR = {
7
- ::Logger::DEBUG => 'DEBUG',
8
- ::Logger::INFO => 'INFO',
9
- ::Logger::WARN => 'WARN',
10
- ::Logger::ERROR => 'ERROR',
11
- ::Logger::FATAL => 'FATAL',
12
- ::Logger::UNKNOWN => '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!('level' => severity)
46
+ json_message.merge!("level" => severity)
47
47
  when Integer
48
- json_message.merge!('level' => SEVERITY_STR.fetch(severity))
48
+ json_message.merge!("level" => SEVERITY_STR.fetch(severity))
49
49
  else
50
- json_message.merge!('level' => SEVERITY_STR.fetch(::Logger::UNKNOWN))
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!('message' => msg)
57
+ json_message.merge!("message" => msg)
58
58
  when Hash
59
- json_message.merge!('message' => 'Empty message') # default message because it is required
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!('message' => msg.inspect)
62
+ json_message.merge!("message" => msg.inspect)
63
63
  end
64
64
  end
65
65
 
@@ -0,0 +1,13 @@
1
+ module Huyegger
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ ensure
10
+ Rails.logger.purge_context! if Rails.logger.is_a?(Huyegger::Logger)
11
+ end
12
+ end
13
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Huyegger
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
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.1.1
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-17 00:00:00.000000000 Z
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: