Module: OxyLogger::Writer

Defined in:
lib/oxy_logger/writer.rb

Defined Under Namespace

Classes: LogDb

Class Method Summary collapse

Class Method Details

.check_pathObject



23
24
25
26
27
# File 'lib/oxy_logger/writer.rb', line 23

def self.check_path
  if OxyLogger.path_to_log.exist? == false
    Dir.mkdir(OxyLogger.path_to_log)
  end
end

.save_to_db(data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/oxy_logger/writer.rb', line 38

def self.save_to_db(data)
  LogDb.create do |log|
    log.run_time = data[:run_time]
    log.class_name = data[:class_name]
    log.date_time = data[:date_time]
    log.method_name = data[:method_name]
    log.result = data[:result]
    log.params = data[:params]
  end
end

.save_to_file(file_name, text) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/oxy_logger/writer.rb', line 29

def self.save_to_file(file_name, text)
  Writer.check_path
  path = [OxyLogger.path_to_log, file_name].join('/')
  
  File.open(path, "a") do  |f|
    f.print("#{text}\n")
  end
end

.write(first_data) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/oxy_logger/writer.rb', line 15

def self.write(first_data)
  data = Formatter.format_data(first_data)
  record = LogRecord.new(data)
  record.save_to == :db ?
    save_to_db(record.for_db) :
    save_to_file(record.file_name, record.for_file)
end