Class: Rack::FluentdLogger
- Inherits:
-
Object
- Object
- Rack::FluentdLogger
- Defined in:
- lib/rack/fluentd_logger.rb,
lib/rack/fluentd_logger_version.rb
Constant Summary collapse
- VERSION =
'0.1.1'
Class Attribute Summary collapse
-
.json_parser ⇒ Object
readonly
Returns the value of attribute json_parser.
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
-
.preprocessor ⇒ Object
readonly
Returns the value of attribute preprocessor.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ FluentdLogger
constructor
A new instance of FluentdLogger.
Constructor Details
#initialize(app) ⇒ FluentdLogger
Returns a new instance of FluentdLogger.
27 28 29 30 31 32 |
# File 'lib/rack/fluentd_logger.rb', line 27 def initialize(app) @app = app @executer = Concurrent::SingleThreadExecutor.new self.class.configure if self.class.logger.nil? end |
Class Attribute Details
.json_parser ⇒ Object (readonly)
Returns the value of attribute json_parser.
11 12 13 |
# File 'lib/rack/fluentd_logger.rb', line 11 def json_parser @json_parser end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
11 12 13 |
# File 'lib/rack/fluentd_logger.rb', line 11 def logger @logger end |
.preprocessor ⇒ Object (readonly)
Returns the value of attribute preprocessor.
11 12 13 |
# File 'lib/rack/fluentd_logger.rb', line 11 def preprocessor @preprocessor end |
Class Method Details
.configure(name: ENV['FLUENTD_NAME'], host: ENV['FLUENTD_HOST'], port: (ENV['FLUENTD_PORT'] || 24_224).to_i, json_parser: ->(str) { JSON.parse(str) }, preprocessor: ->(d) { d }) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/fluentd_logger.rb', line 13 def configure( name: ENV['FLUENTD_NAME'], host: ENV['FLUENTD_HOST'], port: (ENV['FLUENTD_PORT'] || 24_224).to_i, json_parser: ->(str) { JSON.parse(str) }, preprocessor: ->(d) { d } ) @logger = Fluent::Logger::FluentLogger.new(name, host: host, port: port) @json_parser = json_parser @preprocessor = preprocessor end |
Instance Method Details
#call(env) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rack/fluentd_logger.rb', line 34 def call(env) start = Time.now response = @app.call(env) ensure log_request(env, response || $ERROR_INFO, Time.now - start) end |