This file is indexed.

/usr/lib/ruby/vendor_ruby/log4r/outputter/datefileoutputter.rb is in ruby-log4r 1.1.10-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# = DateFileOutputter
#
# Subclass of FileOutputter that changes the log file daily. When a new
# day begins, a new file is created with the date included in the name.
#
# == Usage
#
#   df_out = DateFileOutputter.new('name',
#              :dirname="/tmp", :date_pattern=>"%m-%d" 
#            )
#
# == Rate of Change
#
# A new logfile is created whenever the current time as formatted by the date
# pattern no longer matches the previous time. (This is a simple String 
# comparison.) So, in order to change the frequency of the rollover, just
# alter the date pattern to match how fast the files should be generated. 
# For instance, to generate files by the minute,
#
#   df_out.date_pattern = "%M"
#
# This causes the following files to show up one minute apart, asuming the
# script starts at the 4th minute of the hour:
#
#   file_04.rb
#   file_05.rb
#   file_06.rb
#   ...
#
# The only limitation of this approach is that the precise time cannot be
# recorded as the smallest time interval equals the rollover period for this
# system.

require "log4r/outputter/fileoutputter"
require "log4r/staticlogger"

module Log4r

  # Additional hash arguments are:
  #
  # [<tt>:dirname</tt>]         Directory of the log file
  # [<tt>:date_pattern</tt>]    Time.strftime format string (default is "%Y-%m-%d")

  class DateFileOutputter < FileOutputter
    DEFAULT_DATE_FMT = "%Y-%m-%d"

    def initialize(_name, hash={})
      @DatePattern = (hash[:date_pattern] or hash['date_pattern'] or
                      DEFAULT_DATE_FMT)
      @DateStamp = Time.now.strftime( @DatePattern);
      _dirname = (hash[:dirname] or hash['dirname'])
      # hash[:dirname] masks hash[:filename]
      if _dirname
        if not FileTest.directory?( _dirname)
          raise StandardError, "'#{_dirname}' must be a valid directory", caller
        end
      end

      _filename = (hash[:filename] or hash['filename'])
      if _filename.nil?
        @filebase = File.basename( $0, '.rb') + ".log"
      else
        @filebase = File.basename((hash[:filename] or hash['filename'] or ""))
      end

      # Get rid of the 'nil' in the path
      path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact
      hash[:filename] = hash['filename'] = File.join(path)

      super(_name, hash)
    end

    #######
    private
    #######

    # perform the write
    def write(data)
      change if requiresChange
      super
    end

    # construct a new filename from the DateStamp
    def makeNewFilename
        @DateStamp = Time.now.strftime( @DatePattern);
        @filename = File.join(File.dirname(@filename),
                    @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1'))
    end

    # does the file require a change?
    def requiresChange
      _DateStamp = Time.now.strftime( @DatePattern);
      if not _DateStamp == @DateStamp
        @DateStamp = _DateStamp
        return true
      end
      false
    end

    # change the file 
    def change
      begin
        @out.close
      rescue
        Logger.log_internal {
          "DateFileOutputter '#{@name}' could not close #{@filename}"
        }
      end
      makeNewFilename
      @out = File.new(@filename, (@trunc ? "w" : "a"))
      Logger.log_internal {
        "DateFileOutputter '#{@name}' now writing to #{@filename}"
      }
    end
  end

end