module InfluxdbLogger::Logger

Constants

SEV_LABEL

Severity label for logging. (max 5 char)

Public Class Methods

new(influxdb_tags: [], tags: {}, settings: {}, batch_size: 1000, interval: 1000, async: true) click to toggle source
# File lib/influxdb-logger/logger.rb, line 47
def self.new(influxdb_tags: [], tags: {}, settings: {}, batch_size: 1000, interval: 1000, async: true)
  log_tags = tags.values
  Rails.application.config.log_tags = log_tags
  if Rails.application.config.respond_to?(:action_cable)
    Rails.application.config.action_cable.log_tags = log_tags.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, tags, influxdb_tags)
  logger = ActiveSupport::TaggedLogging.new(inner_logger)
  logger.extend self
end
parse_url(influxdb_url) click to toggle source
# 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

Public Instance Methods

tagged(*tags) { |self| ... } click to toggle source
# File lib/influxdb-logger/logger.rb, line 94
def tagged(*tags)
  @tags = tags.flatten
  yield self
ensure
  flush
end