Class: Flexirest::Logger

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

Class Method Summary collapse

Class Method Details

.debug(message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/flexirest/logger.rb', line 27

def self.debug(message)
  if defined?(Rails) && Rails.logger.present?
    Rails.logger.debug(message)
  elsif @logfile
    if @logfile.is_a?(String)
      File.open(@logfile, "a") do |f|
        f << "#{message}\n"
      end
    else
      @logfile << "#{message}\n"
    end
  else
    @messages << message
  end
end

.error(message) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/flexirest/logger.rb', line 75

def self.error(message)
  if defined?(Rails) && Rails.logger.present?
    Rails.logger.error(message)
  elsif @logfile
    if @logfile.is_a?(String)
      File.open(@logfile, "a") do |f|
        f << "#{message}\n"
      end
    else
      @logfile << "#{message}\n"
    end
  else
    @messages << message
  end
end

.info(message) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flexirest/logger.rb', line 43

def self.info(message)
  if defined?(Rails) && Rails.logger.present?
    Rails.logger.info(message)
  elsif @logfile
    if @logfile.is_a?(String)
      File.open(@logfile, "a") do |f|
        f << "#{message}\n"
      end
    else
      @logfile << "#{message}\n"
    end
  else
    @messages << message
  end
end

.levelObject



19
20
21
22
23
24
25
# File 'lib/flexirest/logger.rb', line 19

def self.level
  if defined?(Rails) && Rails.logger.present?
    Rails.logger.level
  else
    0
  end
end

.logfile=(value) ⇒ Object



6
7
8
# File 'lib/flexirest/logger.rb', line 6

def self.logfile=(value)
  @logfile = value
end

.messagesObject



10
11
12
# File 'lib/flexirest/logger.rb', line 10

def self.messages
  @messages
end

.reset!Object



14
15
16
17
# File 'lib/flexirest/logger.rb', line 14

def self.reset!
  @logfile = nil
  @messages = []
end

.warn(message) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/flexirest/logger.rb', line 59

def self.warn(message)
  if defined?(Rails) && Rails.logger.present?
    Rails.logger.warn(message)
  elsif @logfile
    if @logfile.is_a?(String)
      File.open(@logfile, "a") do |f|
        f << "#{message}\n"
      end
    else
      @logfile << "#{message}\n"
    end
  else
    @messages << message
  end
end