Sha256: cdeaf2b9a3beed06bdfc291e8be81408eaeb8eba393a412d0a758c0d830115c7

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 KB

Contents

unless self.respond_to?("log!")
  $logging = true
  $log = File.new("/tmp/runeblog.log","w")

  def log!(str: "", enter: nil, args: [], pwd: false, dir: false)
    return unless $logging
    time = Time.now.strftime("%H:%M:%S")

    meth = ""
    meth = "#{enter}" if enter

    para = "(#{args.inspect[1..-2]})"

    source = caller[0].sub(/.*\//, " in ").sub(/:/, " line ").sub(/:.*/, "")
    source = "in #{source} (probably liveblog.rb)" if source.include? "(eval)"

    str = "  ... #{str}" unless str.empty?
    indent = " "*12

    $log.puts "#{time} #{meth}#{para}"
    $log.puts "#{indent} #{str} " unless str.empty?
    $log.puts "#{indent} #{source}"
    $log.puts "#{indent} pwd = #{Dir.pwd} " if pwd
    if dir
      files = (Dir.entries('.') - %w[. ..]).join(" ")
      $log.puts "#{indent} dir/* = #{files}"
    end
#   $log.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
    $log.puts
    $log.close
    $log = File.new("/tmp/runeblog.log","a")
  end

#   def log(str: "", enter: nil, args: [], pwd: false, dir: false)
#     return unless $logging
#     time = Time.now.strftime("%H:%M:%S")
#     meth = ""
#     meth = "#{enter}" if enter
#     para = " args: #{args.inspect[1..-2]}"
#     source = caller[0].sub(/.*\//, " in ").sub(/:/, " line ").sub(/:.*/, "")
#     source = " in #{source} (probably liveblog.rb)" if source.include? "(eval)"
#     str = "  ... #{str}" unless str.empty?
#     indent = " "*12
#     STDERR.puts "#{time} #{str} #{meth}"
#     STDERR.puts "#{indent} #{source}"
#     STDERR.puts "#{indent} pwd = #{Dir.pwd} " if pwd
#     if dir
#       files = (Dir.entries('.') - %w[. ..]).join(" ")
#       STDERR.puts "#{indent} dir/* = #{files}"
#     end
#     STDERR.puts "#{indent} #{para} " unless args.empty?
#   # STDERR.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
#     STDERR.puts
#     # $log.close
#     # $log = File.new("/tmp/runeblog.log","a")
#   end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
runeblog-0.2.16 lib/logging.rb
runeblog-0.2.15 lib/logging.rb
runeblog-0.2.14 lib/logging.rb
runeblog-0.2.12 lib/logging.rb
runeblog-0.2.11 lib/logging.rb
runeblog-0.2.10 lib/logging.rb
runeblog-0.2.9 lib/logging.rb
runeblog-0.2.8 lib/logging.rb
runeblog-0.2.7 lib/logging.rb