Module: ClusterBomb::Logging

Included in:
Bomb, Cluster
Defined in:
lib/cluster_bomb/logging.rb

Constant Summary collapse

DEFAULT_LOGFILENAME =
"logs/cb-#{Time.now().strftime('%m-%d-%Y')}.log"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log(msg) ⇒ Object



21
22
23
24
25
26
# File 'lib/cluster_bomb/logging.rb', line 21

def self.log(msg)
  if @logging_enabled && @io
    @io.puts "#{Time.now().strftime('%m-%d-%Y %H:%M:%S')} - #{msg}"
    @io.flush
  end      
end

.log_disableObject



16
17
18
19
20
# File 'lib/cluster_bomb/logging.rb', line 16

def self.log_disable
  @io.close if @io
  @io=nil
  @logging_enabled=false
end

.log_enable(filename = DEFAULT_LOGFILENAME, filemode = 'a') ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/cluster_bomb/logging.rb', line 8

def self.log_enable(filename=DEFAULT_LOGFILENAME, filemode='a')
  filename ||= DEFAULT_LOGFILENAME
  filemode ||= 'a'
  log_dir = File.dirname(filename)
  `mkdir -p #{log_dir}` unless File.exists? log_dir
  @io = File.open(filename,filemode)
  @logging_enabled=true
end

.log_initObject



4
5
6
7
# File 'lib/cluster_bomb/logging.rb', line 4

def self.log_init
  @logging_enabled=false
  @io=nil            
end

.puts(msg) ⇒ Object



27
28
29
30
# File 'lib/cluster_bomb/logging.rb', line 27

def self.puts(msg)      
  Kernel.puts msg
  self.log(msg)
end

Instance Method Details

#puts(msg) ⇒ Object



31
32
33
# File 'lib/cluster_bomb/logging.rb', line 31

def puts(msg)
  Logging.puts(msg)
end