Sha256: a33a7e2cefbd3a9c6f4d8fb50f5376523b88e58e5849269d2e029f11ffe11668

Contents?: true

Size: 1.03 KB

Versions: 25

Compression:

Stored size: 1.03 KB

Contents

require 'time'
require 'logger'

module Sidekiq
  module Logging

    class Pretty < Logger::Formatter
      # Provide a call() method that returns the formatted message.
      def call(severity, time, program_name, message)
        "#{time.utc.iso8601} #{Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{context} #{severity}: #{message}\n"
      end

      def context
        c = Thread.current[:sidekiq_context]
        c ? " #{c}" : ''
      end
    end

    def self.with_context(msg)
      begin
        Thread.current[:sidekiq_context] = msg
        yield
      ensure
        Thread.current[:sidekiq_context] = nil
      end
    end

    def self.initialize_logger(log_target = STDOUT)
      @logger = Logger.new(log_target)
      @logger.level = Logger::INFO
      @logger.formatter = Pretty.new
      @logger
    end

    def self.logger
      @logger || initialize_logger
    end

    def self.logger=(log)
      @logger = (log ? log : Logger.new('/dev/null'))
    end

    def logger
      Sidekiq::Logging.logger
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
sidekiq-2.12.4 lib/sidekiq/logging.rb
sidekiq-2.12.3 lib/sidekiq/logging.rb
sidekiq-2.12.1 lib/sidekiq/logging.rb
sidekiq-2.12.0 lib/sidekiq/logging.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/logging.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/logging.rb
sidekiq-2.11.2 lib/sidekiq/logging.rb
sidekiq-2.11.1 lib/sidekiq/logging.rb
sidekiq-2.11.0 lib/sidekiq/logging.rb
sidekiq-2.10.1 lib/sidekiq/logging.rb
sidekiq-2.10.0 lib/sidekiq/logging.rb
sidekiq-2.9.0 lib/sidekiq/logging.rb
sidekiq-2.8.0 lib/sidekiq/logging.rb
sidekiq-2.7.5 lib/sidekiq/logging.rb
sidekiq-2.7.4 lib/sidekiq/logging.rb
sidekiq-2.7.3 lib/sidekiq/logging.rb
sidekiq-2.7.2 lib/sidekiq/logging.rb
sidekiq-2.7.1 lib/sidekiq/logging.rb
sidekiq-2.7.0 lib/sidekiq/logging.rb
sidekiq-2.6.5 lib/sidekiq/logging.rb