Sha256: c6ee1c4c71425cf3cb318fd68aaa08e71d11ed2812d383358c3a250d4a3d71d3

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'singleton'
require 'jsduck/os'

module JsDuck

  # Central logging of JsDuck
  class Logger
    include Singleton

    attr_accessor :verbose
    attr_accessor :warnings

    def initialize
      @verbose = false
      @warnings = true
      @shown_warnings = {}
    end

    # Prints log message with optional filename appended
    def log(msg, filename=nil)
      if @verbose
        puts msg + " " + format(filename) + "..."
      end
    end

    # Prints warning message.
    #
    # Ignores duplicate warnings - only prints the first one.
    # Works best when --processes=0, but it reduces the amount of
    # warnings greatly also when run multiple processes.
    #
    # Optionally filename and line number will be inserted to message.
    def warn(msg, filename=nil, line=nil)
      msg = "Warning: " + format(filename, line) + " " + msg

      if @warnings && !@shown_warnings[msg]
        $stderr.puts msg
        @shown_warnings[msg] = true
      end
    end

    # Formats filename and line number for output
    def format(filename=nil, line=nil)
      out = ""
      if filename
        out = OS::windows? ? filename.gsub('/', '\\') : filename
        if line
          out += ":#{line}:"
        end
      end
      out
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jsduck-3.0.1 lib/jsduck/logger.rb
jsduck-3.0 lib/jsduck/logger.rb
jsduck-3.0.pre3 lib/jsduck/logger.rb