Module: InfluxdbLogger::Logger
- Defined in:
- lib/influxdb-logger/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(influxdb_tags: [], tags: {}, settings: {}, batch_size: 1000, interval: 1000, async: true) ⇒ Object
- .parse_url(influxdb_url) ⇒ Object
Instance Method Summary collapse
Class Method Details
.new(influxdb_tags: [], tags: {}, settings: {}, batch_size: 1000, interval: 1000, async: true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/influxdb-logger/logger.rb', line 47 def self.new(influxdb_tags: [], tags: {}, settings: {}, batch_size: 1000, interval: 1000, async: true) = .values Rails.application.config. = if Rails.application.config.respond_to?(:action_cable) Rails.application.config.action_cable. = .map do |x| case when x.respond_to?(:call) x when x.is_a?(Symbol) -> (request) { request.send(x) } else -> (request) { x } end end end if ENV["INFLUXDB_URL"] settings = self.parse_url(ENV["INFLUXDB_URL"]).merge(settings) end settings[:batch_size] ||= batch_size settings[:interval] ||= interval settings[:async] = async level = SEV_LABEL.index(Rails.application.config.log_level.to_s.upcase) inner_logger = InfluxdbLogger::InnerLogger.new(settings, level, , ) logger = ActiveSupport::TaggedLogging.new(inner_logger) logger.extend self end |
.parse_url(influxdb_url) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/influxdb-logger/logger.rb', line 77 def self.parse_url(influxdb_url) uri = URI.parse influxdb_url params = CGI.parse uri.query { database: uri.path[1..-1], host: uri.host, port: uri.port, messages_type: params['messages_type'].try(:first), severity_key: params['severity_key'].try(:first), username: params['username'].try(:first), password: params['password'].try(:first), series: params['series'].try(:first), time_precision: params['time_precision'].try(:first), retry: params['retry'].try(:first).to_i } end |
Instance Method Details
#tagged(*tags) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/influxdb-logger/logger.rb', line 94 def tagged(*) @tags = .flatten yield self ensure flush end |