class LogGenerator::Apache
Constants
- AGENT_LIST
- AGENT_LIST_STRING
- HOSTS
- PAGES
- PAGE_CATEGORIES
- RECORDS
Public Class Methods
new()
click to toggle source
# File lib/apache-loggen/base.rb, line 108 def initialize() @pages = [] PAGES.times do @pages << Page.new end @hosts = [] HOSTS.times do @hosts << Host.new end end
Public Instance Methods
format(record, config)
click to toggle source
# File lib/apache-loggen/base.rb, line 141 def format(record, config) if config[:json] then return record.to_json + "\n" else return %[#{record['host']} - #{record['user']} [#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] "#{record['method']} #{record['path']} HTTP/1.1" #{record['code']} #{record['size']} "#{record['referer']}" "#{record['agent']}"\n] end end
generate(context, config)
click to toggle source
# File lib/apache-loggen/base.rb, line 122 def generate(context, config) page = @pages[grand(@pages.size)] host = @hosts[grand(@hosts.size)] record = { 'host' => host.ip, 'user' => '-', 'method' => page.method, 'path' => page.path, 'code' => grand(10000) == 0 ? 500 : page.code, 'referer' => (grand(2) == 0 ? @pages[grand(@pages.size)].path : page.referer) || '-', 'size' => page.size, 'agent' => host.agent, } return format(record, config) end