Sha256: bcbfb30e284108efd414eb34d9768ee8d0039c5d3d870df25f6248f26ff5fa97

Contents?: true

Size: 956 Bytes

Versions: 10

Compression:

Stored size: 956 Bytes

Contents

# DatTCP's logger module acts as a generator for either a debug or null logger.
# This allows the server and workers to always assume they have some logger
# object and not have to worry about conditionally checking if a logger is
# present. The null logger takes all messages and does nothing with them. When
# debug mode is turned off, this logger is used, which keeps the server from
# logging. The debug logger uses an instance of ruby's standard logger and
# writes to STDOUT.
#
require 'logger'

module DatTCP::Logger

  def self.new(debug)
     !!debug ? DatTCP::Logger::Debug.new : DatTCP::Logger::Null.new
  end

  module Debug

    def self.new
      ::Logger.new(STDOUT).tap do |logger|
        logger.progname = "[#{self.name}]"
        logger.datetime_format = "%m/%d/%Y %H:%M:%S%p "
      end
    end

  end

  class Null

    Logger::Severity.constants.each do |name|
      define_method(name.downcase){|*args| } # no-op
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dat-tcp-0.7.0 lib/dat-tcp/logger.rb
dat-tcp-0.6.0 lib/dat-tcp/logger.rb
dat-tcp-0.5.1 lib/dat-tcp/logger.rb
dat-tcp-0.5.0 lib/dat-tcp/logger.rb
dat-tcp-0.4.0 lib/dat-tcp/logger.rb
dat-tcp-0.3.1 lib/dat-tcp/logger.rb
dat-tcp-0.3.0 lib/dat-tcp/logger.rb
dat-tcp-0.2.0 lib/dat-tcp/logger.rb
dat-tcp-0.1.1 lib/dat-tcp/logger.rb
dat-tcp-0.1.0 lib/dat-tcp/logger.rb