Sha256: af15f94d6de73ea01692ada7c6e9f4b58ab3aba067a7fa1f461bd97c6c751203

Contents?: true

Size: 773 Bytes

Versions: 7

Compression:

Stored size: 773 Bytes

Contents

require 'logger'

module QPush
  module Server
    class << self
      STDOUT.sync = true

      def log
        @log ||= Log.new
      end
    end

    # The Log is a simple wrapper for the Logger. It outputs log info in a
    # defined manner to the console.
    #
    class Log
      def initialize
        @log = ::Logger.new(STDOUT)
        @log.formatter = proc do |_severity, _datetime, _progname, msg|
          "#{msg}\n"
        end
      end

      # Creates a new info log message.
      #
      def info(msg)
        @log.info("[ \e[32mOK\e[0m ] #{msg}")
      end

      # Creates a new error log message.
      #
      def err(msg, action: :no_exit)
        @log.info("[ \e[31mER\e[0m ] #{msg}")
        exit 1 if action == :exit
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
qpush-0.1.8 lib/qpush/server/logger.rb
qpush-0.1.7 lib/qpush/server/logger.rb
qpush-0.1.6 lib/qpush/server/logger.rb
qpush-0.1.4 lib/qpush/server/logger.rb
qpush-0.1.2 lib/qpush/server/logger.rb
qpush-0.1.1 lib/qpush/server/logger.rb
qpush-0.1.0 lib/qpush/server/logger.rb