Class: GrayLogger::Middleware
- Inherits:
-
Object
- Object
- GrayLogger::Middleware
- Includes:
- Support
- Defined in:
- lib/gray_logger/middleware.rb
Instance Attribute Summary collapse
-
#gray_logger ⇒ Object
Returns the value of attribute gray_logger.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from Support
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gray_logger/middleware.rb', line 8 def initialize(app, ={}) @app = app configuration = symbolize_keys(.delete(:configuration)) self.gray_logger = if configuration && configuration[:host] && configuration[:port] size = ENV['GRAYLOGGER_SIZE'] || configuration.delete(:size) || "WAN" puts configuration GELF::Logger.new(configuration.delete(:host), configuration.delete(:port), size, configuration) else .delete(:logger) end puts self.gray_logger end |
Instance Attribute Details
#gray_logger ⇒ Object
Returns the value of attribute gray_logger.
6 7 8 |
# File 'lib/gray_logger/middleware.rb', line 6 def gray_logger @gray_logger end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gray_logger/middleware.rb', line 21 def call(env) begin = env["rack.gray_logger.message_store"] = GrayLogger::MessageStore.new(:level => GELF::INFO) status, headers, body = @app.call(env) rescue => e .oder_exception_backtrace = e.backtrace.to_s raise e ensure .status_code = status.to_i puts ..to_hash.inspect gray_logger.notify!(.) unless gray_logger.nil? end end |