325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
# File 'lib/apache-loggen/base.rb', line 325
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
|