Sha256: 2a9f74e89010d5bfc98c84b0f0e9db23d685b9bfedd4cc5e37de7be3f4b50d48

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'logger'
require 'singleton'
require 'svcbase/formatter'

# define our own custom logger
module Core
  # our logger
  class Logger < ::Logger
    include Singleton
    def initialize
      super($stdout)
      self.formatter = Core::Formatters::Log.new
    end

    def none(*_unused)
      # intentional no-op.  Sequel will log things at a defined log level
      # but we want to be able to log long-running queries without logging
      # ALL of them.  this gives us a method to /dev/zero messages for fast
      # queries
    end
  end

  # truncate long parameters, mask password
  class ParamFilter
    def filter(paramhash, maskkeys)
      paramhash.each do |key, value|
        next paramhash[key] = '*' if maskkeys&.include?(key.to_sym)
        next

        case value
        when String
          paramhash[key] = "#{value[1..128]}... (#{value.length})" if value.length > 128
        when Hash, Array
          value = value.to_json.to_s
          paramhash[key] = "#{value[1..128]}... (#{value.length})" if value.length > 128
        end
      end
      paramhash
    end
  end
end

# add a logger method to all objects so that we can access our logger anywhere
class Object
  def log
    Core::Logger.instance
  end

  alias logger log
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
svcbase-0.1.18 lib/svcbase/corelogger.rb
svcbase-0.1.16 lib/svcbase/corelogger.rb