Module: RLogger

Defined in:
lib/r_logger.rb,
lib/r_logger/railtie.rb,
lib/r_logger/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.make(log_file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/r_logger.rb', line 7

def make(log_file)
  @logger ||= {}

  log_file_name = if log_file.class.in? [String, Symbol]
                    log_file_name = log_file.to_sym

                    unless log_file_name.to_s.end_with? ".log"
                      log_file_name = "#{log_file_name}.log"
                    end

                    "#{root_path}/#{log_file_name}"
                  elsif log_file.respond_to? :to_path
                    log_file.to_path
                  else
                    raise Exceptions::UnsupportdParamType.new("log file parameter only support 'File' or 'String' Type.")
                  end

  # 如果已经存在日志对象,则返回已有的日志对象
  @logger[log_file_name] ||= ::Logger.new(log_file_name)
end

.root_pathObject



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

def root_path
  @root ||= "#{Rails.root}/log"
end