In Files

  • webrick/accesslog.rb
  • webrick/httpserver.rb

WEBrick::AccessLog

Public Instance Methods

escape(data) click to toggle source
 
               # File webrick/accesslog.rb, line 67
def escape(data)
  if data.tainted?
    data.gsub(/[[:cntrl:]\]+/) {$&.dump[1...-1]}.untaint
  else
    data
  end
end
            
format(format_string, params) click to toggle source
 
               # File webrick/accesslog.rb, line 49
def format(format_string, params)
  format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
     param, spec = $1, $2
     case spec[0]
     when ?e, ?i, ?n, ?o
       raise AccessLogError,
         "parameter is required for \"#{spec}\"" unless param
       param = params[spec][param] ? escape(param) : "-"
     when ?t
       params[spec].strftime(param || CLF_TIME_FORMAT)
     when ?%
       "%"
     else
       escape(params[spec].to_s)
     end
  }
end
            
setup_params(config, req, res) click to toggle source

This format specification is a subset of mod_log_config of Apache.

http://httpd.apache.org/docs/mod/mod_log_config.html#formats
 
               # File webrick/accesslog.rb, line 25
def setup_params(config, req, res)
  params = Hash.new("")
  params["a"] = req.peeraddr[3]
  params["b"] = res.sent_size
  params["e"] = ENV
  params["f"] = res.filename || ""
  params["h"] = req.peeraddr[2]
  params["i"] = req
  params["l"] = "-"
  params["m"] = req.request_method
  params["n"] = req.attributes
  params["o"] = res
  params["p"] = req.port
  params["q"] = req.query_string
  params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
  params["s"] = res.status       # won't support "%>s"
  params["t"] = req.request_time
  params["T"] = Time.now - req.request_time
  params["u"] = req.user || "-"
  params["U"] = req.unparsed_uri
  params["v"] = config[:ServerName]
  params
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus