lib/legion/logging.rb in legion-logging-0.1.1 vs lib/legion/logging.rb in legion-logging-0.1.2
- old
+ new
@@ -1,90 +1,25 @@
require 'legion/logging/version'
-# require 'legion/logging/logger'
+require 'legion/logging/logger'
+require 'legion/logging/methods'
+require 'legion/logging/builder'
require 'logger'
require 'rainbow'
module Legion
- # Logging Module
module Logging
- attr_accessor :logger
- attr_accessor :color
- # Self Class
class << self
- attr_accessor :log, :logger
+ include Legion::Logging::Methods
+ include Legion::Logging::Builder
+ attr_reader :log, :color
def setup(options = {})
- @log = ::Logger.new($stdout) if options[:log_file].nil?
- @log = ::Logger.new(options[:log_file]) unless options[:log_file].nil?
+ output(options)
log_level(options[:level])
log_format(options)
-
- @log
- end
-
- def log_format(_options)
- @log.formatter = proc do |severity, datetime, _progname, msg|
- "[#{datetime}][#{::Process.pid}] #{severity} #{msg}\n"
- end
- end
-
- def log_level(level = 'debug')
- if level == 'debug'
- @log.level = ::Logger::DEBUG
- elsif level == 'info'
- @log.level = ::Logger::INFO
- elsif level == 'warn'
- @log.level = ::Logger::WARN
- elsif level == 'error'
- @log.level = ::Logger::ERROR
- elsif level == 'fatal'
- @log.level = ::Logger::FATAL
- end
- end
-
- def get(options = {})
- setup(options)
- end
- end
-
- def self.debug(message)
- start_logger if @logger.nil?
- message = Rainbow(message).blue if @color
- @logger.debug(message)
- end
-
- def self.info(message)
- start_logger if @logger.nil?
- message = Rainbow(message).green if @color
- @logger.info(message)
- end
-
- def self.warn(message)
- start_logger if @logger.nil?
- message = Rainbow(message).yellow if @color
- @logger.warn(message)
- end
-
- def self.error(message)
- start_logger if @logger.nil?
- message = Rainbow(message).red if @color
- @logger.error(message)
- end
-
- def self.fatal(message)
- start_logger if @logger.nil?
- message = Rainbow(message).darkred if @color
- @logger.fatal(message)
- end
-
- def self.start_logger
- @color = true
- log_location = $stdout
- @logger = Logger.new(log_location)
- @logger.level = Logger::DEBUG
- @logger.formatter = proc do |severity, datetime, _progname, msg|
- "[#{datetime}][#{::Process.pid}] #{severity} #{msg}\n"
+ @color = options[:color]
+ @color = true if options[:color].nil? && options[:log_file].nil?
end
end
end
end