Sha256: c68cc8ec586c4f029ef4e4abb9a2fef79983d54eeadd8b8c7604c87a56a72f04

Contents?: true

Size: 1.01 KB

Versions: 34

Compression:

Stored size: 1.01 KB

Contents

require 'logger'

module Bitcoin

  # Simple Logger module
  module Logger

    Format = "%s, [%s#%d #%d] %5s -- %s: %s\n".freeze

    module_function

    # Create a logger with given +name+.log in $HOME/.bitcoinrb/log.
    def create(name, level = ::Logger::INFO)
      dir = "#{Bitcoin.base_dir}/log"
      FileUtils.mkdir_p(dir)
      logger = ::Logger.new(dir + "/#{name}.log", 10)
      logger.level = level
      logger.formatter =  proc do |severity, datetime, progname, msg|
        Format % [severity[0..0], format_datetime(datetime), $$,
                  Thread.current.object_id, severity, progname, msg2str(msg)]
      end
      logger
    end

    def self.msg2str(msg)
      case msg
        when ::String
          msg
        when ::Exception
          "#{ msg.message } (#{ msg.class })\n" <<
              (msg.backtrace || []).join("\n")
        else
          msg.inspect
      end
    end

    def format_datetime(time)
      time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
    end

  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
bitcoinrb-1.7.0 lib/bitcoin/logger.rb
bitcoinrb-1.6.0 lib/bitcoin/logger.rb
bitcoinrb-1.5.0 lib/bitcoin/logger.rb
bitcoinrb-1.4.0 lib/bitcoin/logger.rb
bitcoinrb-1.3.0 lib/bitcoin/logger.rb
bitcoinrb-1.2.1 lib/bitcoin/logger.rb
bitcoinrb-1.2.0 lib/bitcoin/logger.rb
bitcoinrb-1.1.1 lib/bitcoin/logger.rb
bitcoinrb-1.1.0 lib/bitcoin/logger.rb
bitcoinrb-1.0.0 lib/bitcoin/logger.rb
bitcoinrb-0.9.0 lib/bitcoin/logger.rb
bitcoinrb-0.8.0 lib/bitcoin/logger.rb
bitcoinrb-0.7.0 lib/bitcoin/logger.rb
bitcoinrb-0.6.0 lib/bitcoin/logger.rb
bitcoinrb-0.5.0 lib/bitcoin/logger.rb
bitcoinrb-0.4.0 lib/bitcoin/logger.rb
bitcoinrb-0.3.2 lib/bitcoin/logger.rb
bitcoinrb-0.3.1 lib/bitcoin/logger.rb
bitcoinrb-0.3.0 lib/bitcoin/logger.rb
bitcoinrb-0.2.9 lib/bitcoin/logger.rb