Class: Incline::Log

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

Overview

A logging wrapper to tag log messages with location information.

Class Method Summary collapse

Class Method Details

.debug(msg = nil, &block) ⇒ Object

Logs a debug message.



10
11
12
# File 'lib/incline/log.rb', line 10

def self.debug(msg = nil, &block)
  safe_log :debug, msg, &block
end

.error(msg = nil, &block) ⇒ Object

Logs an error message.



28
29
30
# File 'lib/incline/log.rb', line 28

def self.error(msg = nil, &block)
  safe_log :error, msg, &block
end

.get_outputObject

Gets the current logging output.



70
71
72
# File 'lib/incline/log.rb', line 70

def self.get_output
  rails&.logger || output
end

.info(msg = nil, &block) ⇒ Object

Logs an info message.



16
17
18
# File 'lib/incline/log.rb', line 16

def self.info(msg = nil, &block)
  safe_log :info, msg, &block
end

.root_pathsObject

Gets a list of paths that are considered root paths for logging purposes.



34
35
36
37
38
39
40
41
42
43
# File 'lib/incline/log.rb', line 34

def self.root_paths
  @root_paths ||=
      begin
        [
            Rails.root.to_s,
            File.expand_path('../../../', __FILE__)
        ]
            .map{|v| v[-1] == '/' ? v : "#{v}/"}
      end
end

.set_output(file) ⇒ Object

Set output to go to a file.

If a file is specified, it will be used for output. This will bypass Rails logging. If file is set to false or nil then the default logging behavior will be used.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/incline/log.rb', line 50

def self.set_output(file)
  if file
    if file.respond_to?(:puts)
      @output = file
      @rails = nil
    elsif file.is_a?(::String)
      @output = File.open(file, 'wt')
      @rails = nil
    else
      raise ArgumentError, 'The file parameter must be an IO-like object, a string path, or a false value.'
    end
  else
    # reset behavior
    remove_instance_variable(:@output) if instance_variable_defined?(:@output)
    remove_instance_variable(:@rails) if instance_variable_defined?(:@rails)
  end
end

.warn(msg = nil, &block) ⇒ Object

Logs a warning message.



22
23
24
# File 'lib/incline/log.rb', line 22

def self.warn(msg = nil, &block)
  safe_log :warn, msg, &block
end