Sha256: 5f7180c5e6781863e7b1b3e0d0745e6781391f441002d1d52b127d34846dc582

Contents?: true

Size: 1.01 KB

Versions: 28

Compression:

Stored size: 1.01 KB

Contents

require 'time'
require 'logger'

module Shoryuken
  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[:shoryuken_context]
        c ? " #{c}" : ''
      end
    end

    def self.with_context(msg)
      Thread.current[:shoryuken_context] = msg
      yield
    ensure
      Thread.current[:shoryuken_context] = nil
    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
      shoryuken::Logging.logger
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
shoryuken-3.1.2 lib/shoryuken/logging.rb
shoryuken-3.1.1 lib/shoryuken/logging.rb
shoryuken-3.1.0 lib/shoryuken/logging.rb
shoryuken-3.0.11 lib/shoryuken/logging.rb
shoryuken-3.0.10 lib/shoryuken/logging.rb
shoryuken-3.0.9 lib/shoryuken/logging.rb
shoryuken-3.0.8 lib/shoryuken/logging.rb
shoryuken-3.0.7 lib/shoryuken/logging.rb
shoryuken-3.0.6 lib/shoryuken/logging.rb
shoryuken-3.0.5 lib/shoryuken/logging.rb
shoryuken-3.0.4 lib/shoryuken/logging.rb
shoryuken-3.0.3 lib/shoryuken/logging.rb
shoryuken-3.0.2 lib/shoryuken/logging.rb
shoryuken-3.0.1 lib/shoryuken/logging.rb
shoryuken-3.0.0 lib/shoryuken/logging.rb
shoryuken-2.1.3 lib/shoryuken/logging.rb
shoryuken-2.1.2 lib/shoryuken/logging.rb
shoryuken-2.1.1 lib/shoryuken/logging.rb
shoryuken-2.1.0 lib/shoryuken/logging.rb
shoryuken-2.0.11 lib/shoryuken/logging.rb