Class: LogGenerator::MyWriter
- Inherits:
-
Object
- Object
- LogGenerator::MyWriter
- Defined in:
- lib/apache-loggen/base.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(filename) ⇒ MyWriter
constructor
A new instance of MyWriter.
- #rotate ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(filename) ⇒ MyWriter
Returns a new instance of MyWriter.
282 283 284 285 286 |
# File 'lib/apache-loggen/base.rb', line 282 def initialize(filename) @filename = filename @io = nil rotate() end |
Instance Method Details
#close ⇒ Object
309 310 311 312 313 |
# File 'lib/apache-loggen/base.rb', line 309 def close() if @filename != nil && @io != nil && !@io.closed? then @io.close end end |
#flush ⇒ Object
306 307 308 |
# File 'lib/apache-loggen/base.rb', line 306 def flush() @io.flush() end |
#rotate ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/apache-loggen/base.rb', line 287 def rotate() if @filename == nil then @io = $stdout return nil else dir = File.dirname(@filename) name = File.basename(@filename, '.*') + '.' + Time.now.strftime('%Y-%m-%d_%H%M%S') + File.extname(@filename) FileUtils.mkdir_p(dir) unless File.exists?(dir) if @io != nil then File.rename(@filename, name) @io.close end @io = open(@filename, "a") return File.join(dir, name) end end |
#write(str) ⇒ Object
303 304 305 |
# File 'lib/apache-loggen/base.rb', line 303 def write(str) return @io.write(str) end |