Class: Spark::Fire

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

Overview

Spark logger functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, verbose: false) ⇒ Fire

Initialize with default stdout output and verbose false



11
12
13
14
# File 'lib/Spark/fire.rb', line 11

def initialize(out: $stdout, verbose: false)
  @out = out
  @verbose = verbose
end

Instance Attribute Details

#outObject (readonly)

returns the medium on where to print the error



8
9
10
# File 'lib/Spark/fire.rb', line 8

def out
  @out
end

#verboseObject (readonly)

Returns the value of attribute verbose.



9
10
11
# File 'lib/Spark/fire.rb', line 9

def verbose
  @verbose
end

Instance Method Details

#error(message) ⇒ Object

Shows an error message



36
37
38
# File 'lib/Spark/fire.rb', line 36

def error(message)
  log.error(message.to_s.red)
end

#important(message) ⇒ Object

Show an important message in upper case



41
42
43
# File 'lib/Spark/fire.rb', line 41

def important(message)
  log.warn(message.to_s.upcase.magenta)
end

#info(message) ⇒ Object

Shows an info message



56
57
58
# File 'lib/Spark/fire.rb', line 56

def info(message)
  log.info(message.to_s.blue)
end

#logObject

Gets the logging object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/Spark/fire.rb', line 17

def log
  out.sync = true
  @log ||= Logger.new(out)

  @log.formatter = proc do |severity, datetime, progname, msg|
    if verbose
      string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
    else
      string = "[#{datetime.strftime('%H:%M:%S')}]: "
    end

    string += "#{msg}\n"

    string
  end
  @log
end

#message(message) ⇒ Object

Shows a regular message



61
62
63
# File 'lib/Spark/fire.rb', line 61

def message(message)
  log.info(message.to_s)
end

#success(message) ⇒ Object

Shows a success message



51
52
53
# File 'lib/Spark/fire.rb', line 51

def success(message)
  log.info(message.to_s.green)
end

#warning(message) ⇒ Object

Shows a warning message



46
47
48
# File 'lib/Spark/fire.rb', line 46

def warning(message)
  log.warn(message.to_s.yellow)
end