Class: Locomotive::Common::Logger
- Inherits:
-
Object
- Object
- Locomotive::Common::Logger
- Defined in:
- lib/locomotive/common/logger.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#setup(log_file_full_path = nil) ⇒ Object
Setup the single instance of the ruby logger.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
10 11 12 |
# File 'lib/locomotive/common/logger.rb', line 10 def initialize self.logger = nil end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/locomotive/common/logger.rb', line 8 def logger @logger end |
Class Method Details
.close ⇒ Object
49 50 51 |
# File 'lib/locomotive/common/logger.rb', line 49 def self.close instance.logger.close end |
.instance ⇒ Object
36 37 38 |
# File 'lib/locomotive/common/logger.rb', line 36 def self.instance @@instance ||= new end |
.setup(*args) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/locomotive/common/logger.rb', line 40 def self.setup(*args) if args.size > 1 puts '[DEPRECATION] Logger.setup(path, stdout=false) is deprecated. ' \ 'Please use Logger.setup(log_file_full_path) instead, ' \ 'like: /home/locomotivecms/log/server.log' end instance.setup args.first end |
Instance Method Details
#setup(log_file_full_path = nil) ⇒ Object
Setup the single instance of the ruby logger.
@param[ optional ] [ String ] path The path to the log file, full path with log file name Sample /home/locomotivecms/log/server.log (default: nil => Stdout)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/locomotive/common/logger.rb', line 19 def setup(log_file_full_path = nil) require 'logger' output = if log_file_full_path log_file_path log_file_full_path else $stdout end self.logger = ::Logger.new(output).tap do |log| log.level = ::Logger::DEBUG log.formatter = proc do |_severity, _datetime, _progname, msg| "#{msg}\n" end end end |