Class: RbRotate::Log

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

Overview

Logfile.

Constant Summary collapse

@@self =

Singletone instance.

nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Log

Constructor.



48
49
50
# File 'lib/rb.rotate/log.rb', line 48

def initialize(path)
    @path = path
end

Class Method Details

.getObject

Returns its singletone instance.



28
29
30
31
32
33
34
# File 'lib/rb.rotate/log.rb', line 28

def self.get
    if @@self.nil?
        @@self = self::new(Configuration::get.paths[:"log file"])
    end
    
    return @@self
end

.write(message, caller = nil) ⇒ Object

Alias for #write.



40
41
42
# File 'lib/rb.rotate/log.rb', line 40

def self.write(message, caller = nil)
    self::get.write(message, caller)
end

Instance Method Details

#write(message, caller = nil) ⇒ Object

Writes to log.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rb.rotate/log.rb', line 56

def write(message, caller = nil)
    output = "[" << Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << "] "
    if caller
        output << caller.class.name << ": "
    end
    output << message << "\n"
    
    ::File.open(@path, "a") do |io|
        io.write(output)
    end
end