Sha256: 5bbaad8d9471a1a334b4eb2ae5f794c1ef0736542ca8894c4d51c5679c8d49f7

Contents?: true

Size: 1.76 KB

Versions: 13

Compression:

Stored size: 1.76 KB

Contents

require 'logatron/message_formatting'
require 'logatron/const'
require 'logatron/configuration'
require 'logatron/basic_scoped_logger'
module Logatron
  class BasicLogger
    include Logatron::Formatting

    def level=(a_level)
      Logatron.configuration.logger.level = SEVERITY_MAP[a_level]
    end

    def info(msg)
      write(format_log(msg: msg, severity: INFO), SEVERITY_MAP[INFO])
    end

    def warn(msg)
      write(format_log(msg: msg, severity: WARN), SEVERITY_MAP[WARN])
    end

    def debug(msg)
      write(format_log(msg: msg, severity: DEBUG), SEVERITY_MAP[DEBUG])
    end

    def invalid_use(msg)
      write(format_log(msg: msg, severity: INVALID_USE), SEVERITY_MAP[INVALID_USE])
    end

    def error(msg)
      write(format_log(msg: msg, severity: ERROR), SEVERITY_MAP[ERROR])
    end

    def critical(msg)
      write(format_log(msg: msg, severity: CRITICAL), SEVERITY_MAP[CRITICAL])
    end

    def fatal(msg)
      write(format_log(msg: msg, severity: FATAL), SEVERITY_MAP[FATAL])
    end

    def log(id: '-', site: '-', msg: '-', severity: INFO, request: '-', status: '-', source: '-', &block)
      ml = Logatron::BasicScopedLogger.new(self)
      start = Time.now
      begin
        res = block.call(ml)
        write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request), SEVERITY_MAP[severity])
        res
      rescue Exception => e
        write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request), SEVERITY_MAP[severity])
        ml.flush
        raise e
      end
    end

    def write(string, severity)
      Logatron.configuration.logger.log(severity, string)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
logatron-0.16.1 lib/logatron/basic_logger.rb
logatron-0.16.0 lib/logatron/basic_logger.rb
logatron-0.15.0 lib/logatron/basic_logger.rb
logatron-0.14.0 lib/logatron/basic_logger.rb
logatron-0.13.0 lib/logatron/basic_logger.rb
logatron-0.12.0 lib/logatron/basic_logger.rb
logatron-0.11.0 lib/logatron/basic_logger.rb
logatron-0.10.0 lib/logatron/basic_logger.rb
logatron-0.9.0 lib/logatron/basic_logger.rb
logatron-0.8.0 lib/logatron/basic_logger.rb
logatron-0.7.0 lib/logatron/basic_logger.rb
logatron-0.6.0 lib/logatron/basic_logger.rb
logatron-0.5.0 lib/logatron/basic_logger.rb