Sha256: aebc87cbc68ec1fc8aeb7c28576b5c545ebf46abd095e0192834c15170ce338f

Contents?: true

Size: 1.22 KB

Versions: 62

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'logger'

# include this to add ability to log at different levels
module Logging
  # @return [::Logger]
  def logger
    # @sg-ignore
    @logger ||= if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
                  # @sg-ignore
                  Rails.logger
                else
                  ::Logger.new($stdout, level: log_level)
                end
  end

  # @param message [String,nil]
  #
  # @return [void]
  def error(message = nil, &block)
    logger.error(message, &block)
  end

  # @param message [String,nil]
  #
  # @return [void]
  def warn(message = nil, &block)
    logger.warn(message, &block)
  end

  # @param message [String,nil]
  #
  # @return [void]
  def info(message = nil, &block)
    logger.info(message, &block)
  end

  # @param message [String,nil]
  #
  # @return [void]
  def debug(message = nil, &block)
    logger.debug(message, &block)
  end

  # @param message [String,nil]
  #
  # @return [void]
  def finer(message = nil, &block)
    # No such level by default
    #
    # logger.finer(message, &block)
  end

  private

  # @sg-ignore
  # @return [Symbol]
  def log_level
    # @sg-ignore
    ENV.fetch('LOG_LEVEL', 'INFO').downcase.to_sym
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
checkoff-0.201.0 lib/checkoff/internal/logging.rb
checkoff-0.200.0 lib/checkoff/internal/logging.rb
checkoff-0.199.0 lib/checkoff/internal/logging.rb
checkoff-0.198.0 lib/checkoff/internal/logging.rb
checkoff-0.197.0 lib/checkoff/internal/logging.rb
checkoff-0.196.0 lib/checkoff/internal/logging.rb
checkoff-0.195.0 lib/checkoff/internal/logging.rb
checkoff-0.194.0 lib/checkoff/internal/logging.rb
checkoff-0.193.0 lib/checkoff/internal/logging.rb
checkoff-0.192.0 lib/checkoff/internal/logging.rb
checkoff-0.191.0 lib/checkoff/internal/logging.rb
checkoff-0.190.0 lib/checkoff/internal/logging.rb
checkoff-0.189.0 lib/checkoff/internal/logging.rb
checkoff-0.188.0 lib/checkoff/internal/logging.rb
checkoff-0.187.0 lib/checkoff/internal/logging.rb
checkoff-0.186.0 lib/checkoff/internal/logging.rb
checkoff-0.185.0 lib/checkoff/internal/logging.rb
checkoff-0.184.0 lib/checkoff/internal/logging.rb
checkoff-0.183.0 lib/checkoff/internal/logging.rb
checkoff-0.182.0 lib/checkoff/internal/logging.rb