Module: ActFluentLoggerRails::Logger
- Defined in:
- lib/act-fluent-logger-rails/logger.rb
Constant Summary collapse
- SEV_LABEL =
Severity label for logging. (max 5 char)
%w(DEBUG INFO WARN ERROR FATAL ANY)
Class Method Summary collapse
- .new(config_file: Rails.root.join("config", "fluent-logger.yml"), log_tags: {}) ⇒ Object
- .parse_url(fluentd_url) ⇒ Object
Instance Method Summary collapse
Class Method Details
.new(config_file: Rails.root.join("config", "fluent-logger.yml"), log_tags: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 14 def self.new(config_file: Rails.root.join("config", "fluent-logger.yml"), log_tags: {}) Rails.application.config. = [ ->(request) { request } ] unless .empty? fluent_config = if ENV["FLUENTD_URL"] self.parse_url(ENV["FLUENTD_URL"]) else YAML.load(ERB.new(config_file.read).result)[Rails.env] end settings = { tag: fluent_config['tag'], host: fluent_config['fluent_host'], port: fluent_config['fluent_port'], messages_type: fluent_config['messages_type'], } level = SEV_LABEL.index(Rails.application.config.log_level.to_s.upcase) logger = ActFluentLoggerRails::FluentLogger.new(settings, level, ) logger = ActiveSupport::TaggedLogging.new(logger) logger.extend self end |
.parse_url(fluentd_url) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 33 def self.parse_url(fluentd_url) uri = URI.parse fluentd_url params = CGI.parse uri.query { host: uri.host, port: uri.port, tag: uri.path[1..-1], messages_type: params["messages_type"].try(:first) }.stringify_keys end |
Instance Method Details
#tagged(*tags) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 45 def tagged(*) @request = [0][0] yield self ensure flush end |