Class: Semlogger::Rotate

Inherits:
Object show all
Defined in:
lib/semlogger/rotate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Rotate

Returns a new instance of Rotate.



6
7
8
# File 'lib/semlogger/rotate.rb', line 6

def initialize filename
	@filename = filename
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



2
3
4
# File 'lib/semlogger/rotate.rb', line 2

def file
  @file
end

Instance Method Details

#closeObject



21
22
23
24
# File 'lib/semlogger/rotate.rb', line 21

def close
	@file.close
	@file = nil
end

#filenameObject



4
# File 'lib/semlogger/rotate.rb', line 4

def filename()  @filename.dup  end

#open_ifObject



10
11
12
13
14
15
# File 'lib/semlogger/rotate.rb', line 10

def open_if
	name = Time.now.strftime( @filename).gsub /%\$/, $$.to_s
	close  if @file and name != @file.path
	@file = File.open name, 'a'  unless @file
	@file
end

#write(message) ⇒ Object



17
18
19
# File 'lib/semlogger/rotate.rb', line 17

def write message
	open_if.write message
end