Sha256: a1f3ffdc1445a87c930fa00bc30f2cfeb27389810a118d367c9f2e7b53e3a8d5

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

module Envoy

  TRACE = 5
  DEBUG = 4
  INFO  = 3
  WARN  = 2
  ERROR = 1
  FATAL = 0

  VERBOSITIES = "FEWIDT"

  def self.verbosity
    @verbosity
  end

  def self.verbosity= (num)
    @verbosity = [0, [5, num].min].max
  end

  def self.log (level, text, io = STDERR)
    return unless io
    level = Envoy.const_get(level.upcase) unless level.is_a?(Numeric)
    return unless level <= verbosity
    message = [
      Time.now.strftime("%F %T"),
      VERBOSITIES[level],
      text
    ].compact.join(" ")
    io.puts message
    io.flush
  end

  def self.find_file (name)
    dirs = Dir.pwd.split("/")
    r = dirs.reduce([]) do |m, x|
      [[*m[0], x], *m]
    end.map do |p|
      p.join("/") + "/#{name}"
    end.each do |p|
      return p if File.exist?(p)
    end
    false
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
envoy-proxy-1.0.3 lib/envoy/utils.rb
envoy-proxy-1.0.1 lib/envoy/utils.rb