Sha256: aebc87cbc68ec1fc8aeb7c28576b5c545ebf46abd095e0192834c15170ce338f

Contents?: true

Size: 1.22 KB

Versions: 82

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

82 entries across 82 versions & 1 rubygems

Version Path
checkoff-0.222.0 lib/checkoff/internal/logging.rb
checkoff-0.221.0 lib/checkoff/internal/logging.rb
checkoff-0.220.0 lib/checkoff/internal/logging.rb
checkoff-0.219.0 lib/checkoff/internal/logging.rb
checkoff-0.218.0 lib/checkoff/internal/logging.rb
checkoff-0.217.0 lib/checkoff/internal/logging.rb
checkoff-0.216.0 lib/checkoff/internal/logging.rb
checkoff-0.215.0 lib/checkoff/internal/logging.rb
checkoff-0.214.0 lib/checkoff/internal/logging.rb
checkoff-0.213.0 lib/checkoff/internal/logging.rb
checkoff-0.212.0 lib/checkoff/internal/logging.rb
checkoff-0.211.0 lib/checkoff/internal/logging.rb
checkoff-0.210.0 lib/checkoff/internal/logging.rb
checkoff-0.209.0 lib/checkoff/internal/logging.rb
checkoff-0.208.0 lib/checkoff/internal/logging.rb
checkoff-0.207.0 lib/checkoff/internal/logging.rb
checkoff-0.206.0 lib/checkoff/internal/logging.rb
checkoff-0.205.0 lib/checkoff/internal/logging.rb
checkoff-0.204.0 lib/checkoff/internal/logging.rb
checkoff-0.203.0 lib/checkoff/internal/logging.rb