Class: MiniProgram::RLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_program/r_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRLogger

Returns a new instance of RLogger.

Raises:

  • (Exceptions::InitializeDenied)


3
4
5
# File 'lib/mini_program/r_logger.rb', line 3

def initialize
  raise Exceptions::InitializeDenied.new("please use 'RLogger.make' instead of 'RLogger.new'")
end

Class Method Details

.log_filename(given_filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mini_program/r_logger.rb', line 16

def log_filename(given_filename)
  return STDOUT if ENV["RAILS_LOG_TO_STDOUT"].present?

  if given_filename.class.in? [String, Symbol]
    unless given_filename.end_with? ".log"
      given_filename = "#{given_filename}.log"
    end

    Rails.root.join("log/#{given_filename}")
  elsif given_filename.respond_to? :to_path
    given_filename.to_path
  else
    raise Exception::UnsupportedParamType.new("\"log filename parameter must be a String type or a Symbol\"")
  end
end

.make(given_filename) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/mini_program/r_logger.rb', line 8

def make(given_filename)
  filename = log_filename(given_filename)

  # 如果已经存在日志对象,则返回已有的日志对象
  logger = Logger.new(filename)
  ActiveSupport::TaggedLogging.new(logger)
end