Class: QuickbaseLogger::Logger

Inherits:
Object
  • Object
show all
Includes:
QuickbaseRecord::Model
Defined in:
lib/quickbase_logger/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Logger

Returns a new instance of Logger.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/quickbase_logger/logger.rb', line 7

def initialize(options={})
  raise ArgumentError.new("QuickbaseLogger::Logger.new must receive a :related_script argument.") unless options[:related_script]

  @log = []
  @start = "#{formatted_date} #{formatted_time}"

  file_name = options.fetch(:file_name, 'quickbase_logger_default')
  @text_logger = ::Logger.new("#{formatted_logger_path}#{file_name}.log", "monthly") # standard ruby Logger instance
  @text_logger.info("START")
  super
end

Instance Attribute Details

#text_loggerObject

Returns the value of attribute text_logger.



5
6
7
# File 'lib/quickbase_logger/logger.rb', line 5

def text_logger
  @text_logger
end

Instance Method Details

#error(message) ⇒ Object



41
42
43
# File 'lib/quickbase_logger/logger.rb', line 41

def error(message)
  log << "Error [#{formatted_time}]: #{message}"
end

#info(message) ⇒ Object



33
34
35
# File 'lib/quickbase_logger/logger.rb', line 33

def info(message)
  log << "Info [#{formatted_time}]: #{message}"
end

#log_to_quickbaseObject

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/quickbase_logger/logger.rb', line 19

def log_to_quickbase
  raise ArgumentError.new("#log_to_quickbase() must be given a block. Code run inside that block will be logged to the QuickBase application.") unless block_given?

  begin
    yield
    log_success_to_text_file
    log_success_to_quickbase
  rescue => err
    log_failure_to_text_file(err)
    log_failure_to_quickbase(err)
    raise err
  end
end

#warn(message) ⇒ Object



37
38
39
# File 'lib/quickbase_logger/logger.rb', line 37

def warn(message)
  log << "Warn [#{formatted_time}]: #{message}"
end