Class: Logoris

Inherits:
Object
  • Object
show all
Defined in:
lib/logoris.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ void

Parameters:

  • args (Hash) (defaults to: {})

    Logoris options

  • options (Hash)

    a customizable set of options



21
22
23
24
25
26
27
28
# File 'lib/logoris.rb', line 21

def initialize(args={})
  @out_file   = false # Do not log stdout events to a file by default.
  @error_file = false # Do not log stderr events to a file by default.
  @log_file   = false # Do not log both stdout and stderr events to a file by default.
  out_file    = args[:out_file]   if args[:out_file]   # Set file for stdout, if given.
  error_file  = args[:error_file] if args[:error_file] # Set file for stderr, if given.
  log_file    = args[:log_file]   if args[:log_file]   # Set file for stdout and stderr, if given.
end

Instance Attribute Details

#error_fileString

The optional error_file to log stderr events.

Returns:

  • (String)


11
12
13
# File 'lib/logoris.rb', line 11

def error_file
  @error_file
end

#log_fileString

The optional error_file to log both stdout and stderr events.

Returns:

  • (String)


15
16
17
# File 'lib/logoris.rb', line 15

def log_file
  @log_file
end

#out_fileString

The optional out_file to log stdout events.

Returns:

  • (String)


7
8
9
# File 'lib/logoris.rb', line 7

def out_file
  @out_file
end

Instance Method Details

#error(message) ⇒ void

This method returns an undefined value.

Parameters:

  • message (String)


40
41
42
43
44
# File 'lib/logoris.rb', line 40

def error(message)
  STDERR.puts message
  to_log(@error_file, message) if @error_file
  to_log(@log_file, message)   if @log_file
end

#log_exists?(file) ⇒ Boolean

Parameters:

  • file (String)

Returns:

  • (Boolean)


77
78
79
# File 'lib/logoris.rb', line 77

def log_exists?(file)
  File.exists?(file)
end

#out(message) ⇒ void

This method returns an undefined value.

Parameters:

  • message (String)


32
33
34
35
36
# File 'lib/logoris.rb', line 32

def out(message)
  STDOUT.puts message
  to_log(@out_file, message) if @out_file
  to_log(@log_file, message) if @log_file
end

#to_log(file, message) ⇒ void

This method returns an undefined value.

Parameters:

  • file (String)
  • message (String)


70
71
72
73
# File 'lib/logoris.rb', line 70

def to_log(file, message)
  File.open(file, 'a') { |f| f.puts message }
  to_log(@log_file, message) if @log_file
end