This file is indexed.

/usr/share/glark/log.rb is in glark 1.8.0-1.

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

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/ruby -w
# -*- ruby -*-

# -------------------------------------------------------
# Logging
# -------------------------------------------------------

# Very minimal logging output. If verbose is set, this displays the method and
# line number whence called. It can be a mixin to a class, which displays the
# class and method from where it called. If not in a class, it displays only the
# method.

# All kids love log.
class Log

  VERSION = "1.0.1"

  attr_accessor :quiet
  
  module Severity
    DEBUG = 0
    INFO  = 1
    WARN  = 2
    ERROR = 3
    FATAL = 4
  end

  include Log::Severity

  WHENCE_RE = Regexp.new('(.*):(\d+)(?::in\s+\`(.*)\\\')?', Regexp::EXTENDED)

  def initialize
    @width   = 0
    @output  = $stdout
    @fmt     = "[%s:%04d] {%s}"
    @level   = FATAL
    @quiet   = false
  end
    
  def verbose=(v)
    @level = case v
             when TrueClass 
               DEBUG
             when FalseClass 
               FATAL
             when Integer
               v
             end
  end

  def verbose
    @level <= DEBUG
  end

  def level=(lvl)
    @level = lvl
  end

  # Assigns output to the given stream.
  def output=(io)
    @output = io
  end

  # Assigns output to a file with the given name. Returns the file; client
  # is responsible for closing it.
  def outfile=(f)
    @output = if f.kind_of?(IO) then f else File.new(f, "w") end
  end

  # Creates a printf format for the given widths, for aligning output.
  def set_widths(file_width, line_width, cls_width, meth_width)
    @fmt = "[%#{file_width}s:%#{line_width}d] {%#{cls_width}s\#%#{meth_width}s}"
  end

  def get_whence(c, classname)
    md   = WHENCE_RE.match(c)

    file = md[1].sub(%r{ .*/ }msx, "")
    line = md[2]
    cls  = classname || ""
    meth = md[3] || "???"
    [ file, line, cls, meth ]
  end

  # Logs the given message.
  def log(msg = "", level = DEBUG, depth = 1, cname = nil, &blk)
    if level >= @level
      c = caller(depth)[0]
      file, line, cls, meth = get_whence(c, cname)
      print_formatted(file, line, cls, meth, msg, level, &blk)
    end
    true
  end

  # Shows the current stack.
  def stack(msg = "", level = DEBUG, depth = 1, cname = nil, &blk)
    if level >= @level
      stk = caller(depth)
      stk.shift
      for c in stk
        file, line, cls, meth = get_whence(c, cname)
        print_formatted(file, line, cls, meth, msg, level, &blk)
        msg = '"'
        blk = nil
      end
    end
    true
  end

  def print_formatted(file, line, cls, meth, msg, level, &blk)
    hdr = sprintf @fmt, file, line, cls, meth

    if blk
      x = blk.call
      if x.kind_of?(String)
        msg = x
      else
        return
      end
    end
    @output.puts hdr + " " + msg.to_s.chomp
  end

  # by default, class methods delegate to a single app-wide log.

  @@log = Log.new

  def self.quiet
    @@log.quiet
  end

  def self.quiet=(q)
    @@log.quiet = q
  end

  def self.verbose
    @@log.verbose
  end

  def self.verbose=(v)
    @@log.verbose = v && v != 0 ? DEBUG : FATAL
  end

  def self.level=(lvl)
    @@log.level = lvl
  end

  def self.set_widths(file_width, line_width, cls_width, meth_width)
    @@log.set_widths(file_width, line_width, cls_width, meth_width)
  end

  def self.log(msg = "", level = DEBUG, depth = 1, cname = nil, &blk)
    @@log.log(msg, level, depth + 1, cname, &blk)
  end

  def self.stack(msg = "", level = DEBUG, depth = 1, cname = nil, &blk)
    @@log.stack(msg, level, depth, cname, &blk)
  end

  def self.warn(msg, depth = 1, cname = nil, &blk)
    write("WARNING: " + msg, depth + 1, cname, &blk)
  end

  def self.error(msg, depth = 1, cname = nil, &blk)
    if verbose
      stack(msg, Log::ERROR, depth + 1, cname, &blk)
    else
      $stderr.puts "ERROR: " + msg
    end
  end

  def self.write(msg, depth = 1, cname = nil, &blk)
    if verbose
      stack(msg, Log::WARN, depth + 1, cname, &blk)
    elsif quiet
      # nothing
    else
      $stderr.puts msg
    end
  end

end


module Loggable

  # Logs the given message, including the class whence invoked.
  def log(msg = "", level = Log::DEBUG, depth = 1, &blk)
    Log.log(msg, level, depth + 1, self.class.to_s, &blk)
  end
  
  def stack(msg = "", level = Log::DEBUG, depth = 1, &blk)
    Log.stack(msg, level, depth + 1, self.class.to_s, &blk)
  end

  def warn(msg = "", depth = 1, &blk)
    Log.warn(msg, depth + 1, self.class.to_s, &blk)
  end

  def error(msg = "", depth = 1, &blk)
    Log.error(msg, depth + 1, self.class.to_s, &blk)
  end

  def write(msg = "", depth = 1, &blk)
    Log.write(msg, depth + 1, self.class.to_s, &blk)
  end

end