Sha256: 449770865d67f1415054d504debc4c6fdd4ad2571c7bd4075cdd392b1d32dd25

Contents?: true

Size: 1.53 KB

Versions: 60

Compression:

Stored size: 1.53 KB

Contents

# :nodoc:
# Version:: $Id$

require "log4r/outputter/iooutputter"
require "log4r/staticlogger"

module Log4r

  # Convenience wrapper for File. Additional hash arguments are:
  #
  # [<tt>:filename</tt>]   Name of the file to log to.
  # [<tt>:trunc</tt>]      Truncate the file?
  class FileOutputter < IOOutputter
    attr_reader :trunc, :filename

    def initialize(_name, hash={})
      super(_name, nil, hash)

      @trunc = Log4rTools.decode_bool(hash, :trunc, false)
      _filename = (hash[:filename] or hash['filename'])
      @create = Log4rTools.decode_bool(hash, :create, true)

      if _filename.class != String
        raise TypeError, "Argument 'filename' must be a String", caller
      end

      # file validation
      if FileTest.exist?( _filename )
        if not FileTest.file?( _filename )
          raise StandardError, "'#{_filename}' is not a regular file", caller
        elsif not FileTest.writable?( _filename )
          raise StandardError, "'#{_filename}' is not writable!", caller
        end
      else # ensure directory is writable
        dir = File.dirname( _filename )
        if not FileTest.writable?( dir )
          raise StandardError, "'#{dir}' is not writable!"
        end
      end

      @filename = _filename
      if ( @create == true ) then
	@out = File.new(@filename, (@trunc ? "wb" : "ab")) 
	Logger.log_internal {
	  "FileOutputter '#{@name}' writing to #{@filename}"
	}
      else
	Logger.log_internal {
	  "FileOutputter '#{@name}' called with :create == false, #{@filename}"
	}
      end
    end

  end
  
end

Version data entries

60 entries across 52 versions & 11 rubygems

Version Path
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
mtn_log4r-1.1.12 lib/log4r/outputter/fileoutputter.rb
mtn_log4r-1.1.11 lib/log4r/outputter/fileoutputter.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-shell-0.2.6 vendor/bundle/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-shell-0.2.5 vendor/bundle/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/log4r-1.1.10/lib/log4r/outputter/fileoutputter.rb
log4r-1.1.10 lib/log4r/outputter/fileoutputter.rb