Sha256: 4e3a4f5f85fd090ccf643c16936d58b0a0868242399cc6e6e31501cc74ca215f

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require 'legion/logging/version'
# require 'legion/logging/logger'

require 'logger'
require 'rainbow'

module Legion
  # Logging Module
  module Logging
    attr_accessor :logger
    attr_accessor :color
    # Self Class
    class << self
      attr_accessor :logger
      @logger = ::Logger.new($stdout)
    end
    def self.test(message)
      start_logger if @logger.nil?
      message = Rainbow(message).aliceblue if @color
      @logger.debug(message)
    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
      daemonize = false

      if daemonize
        @color = false
        log_location = '/var/log/legion.log'
      else
        @color = true
        log_location = $stdout
      end
      @logger = Logger.new(log_location)
      @logger.level = Logger::DEBUG
      @logger.formatter = proc do |severity, datetime, _progname, msg|
        # default
        # SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
        "[#{datetime}][#{::Process.pid}] #{severity} #{msg}\n"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-logging-0.1.0 lib/legion/logging.rb