class LogGenerator::Generator

Constants

DEFAULT_CONFIG

Public Class Methods

execute(conf={}, gen_obj=nil, &block) click to toggle source
# File lib/apache-loggen/base.rb, line 324
def self.execute(conf={}, gen_obj=nil, &block)
  
  config = DEFAULT_CONFIG.merge(conf)
  writer = MyWriter.new(config[:filename])
  gen_kick = gen_obj && gen_obj.is_a?(Base)

  # 実行
  last_rotate = Time.now.to_i
  Executors.exec(config) do | context |

    if config[:rotate] > 0 && (last_rotate + config[:rotate]) <= Time.now.to_i then
      rotated_file = writer.rotate()
      if config[:progress] then
        $stderr.write "\rfile rotate. rename to #{rotated_file}\n"
      end
      last_rotate = Time.now.to_i
    end
    
    # レコード生成
    record = gen_obj.generate(context, config) if gen_kick
    record = block.call(context, config, record) if block

    # 出力
    writer.write(record)
    writer.flush()

    not (config[:limit] > 0 && config[:limit] <= context[:total_count]+1)

  end
  writer.close

end