Sha256: 21efcdc413c371426f6e82de34a4018cba88bb145359c098329f6d2ea973b127

Contents?: true

Size: 807 Bytes

Versions: 5

Compression:

Stored size: 807 Bytes

Contents

require "singleton"
require_relative "version"

class Logger
  include Singleton
  @attr_verbose = "yes"

  def set_verbose(value)
    @attr_verbose = value
  end

  def self.verbose(msg)
    print msg if @attr_verbose == "yes"
    @logfile&.write(msg)
  end

  def self.verboseln(msg)
    verbose(msg + "\n")
  end

  def log(msg)
    verbose(msg)
  end

  def logln(msg)
    verboseln(msg)
  end

  def self.create(logpath)
    @logfile = File.open(logpath, 'w')
    @logfile.write('=' * 50 + "\n")
    @logfile.write("Created by : #{Asker::NAME}")
    @logfile.write(" (version #{Asker::VERSION})\n")
    @logfile.write("File       : #{File.basename(logpath)}\n")
    @logfile.write("Time       : #{Time.new}\n")
    @logfile.write('=' * 50 + "\n\n")
  end

  def self.close
    @logfile.close
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
asker-tool-2.5.9 lib/asker/logger.rb
asker-tool-2.5.8 lib/asker/logger.rb
asker-tool-2.5.7 lib/asker/logger.rb
asker-tool-2.5.6 lib/asker/logger.rb
asker-tool-2.5.5 lib/asker/logger.rb