Sha256: 046fa1827ca8c33881142a2c1e1c076d130f7baa481ad7b986ff5b427156ff65

Contents?: true

Size: 597 Bytes

Versions: 11

Compression:

Stored size: 597 Bytes

Contents

# frozen_string_literal: true

require 'logger'

class PgExport
  class BuildLogger
    FORMATS = {
      plain: ->(_, _, _, message) { "#{message}\n" },
      muted: ->(*) { raise 'Do not initialize logger when it is muted' },
      timestamped: lambda do |severity, datetime, progname, message|
        "#{datetime} #{Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{progname} #{severity}: #{message}\n"
      end
    }.freeze

    def self.call(stream:, format:)
      Logger.new(stream).tap do |logger|
        logger.formatter = FORMATS.fetch(format.to_sym)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pg_export-1.0.0.rc3 lib/pg_export/build_logger.rb
pg_export-1.0.0.rc2 lib/pg_export/build_logger.rb
pg_export-1.0.0.rc1 lib/pg_export/build_logger.rb
pg_export-0.7.7 lib/pg_export/build_logger.rb
pg_export-0.7.6 lib/pg_export/build_logger.rb
pg_export-0.7.5 lib/pg_export/build_logger.rb
pg_export-0.7.4 lib/pg_export/build_logger.rb
pg_export-0.7.3 lib/pg_export/build_logger.rb
pg_export-0.7.2 lib/pg_export/build_logger.rb
pg_export-0.7.1 lib/pg_export/build_logger.rb
pg_export-0.7.0 lib/pg_export/build_logger.rb