class Pantheios::Services::ColouredConsoleLogService

A class that fulfils the Pantheios LogService protocol that allows all severities and logs to the console (via +$stdout+ and +$stderr+)

NOTE: The LogService protocol is implemented by a class that provides the instance methods +severity_logged?(severity : Object) : boolean+ and +log(severity : Object, t : Time, prefix : String|Array, msg : String)+

Public Class Methods

requires_prefix?() click to toggle source
# File lib/pantheios/services/coloured_console_log_service.rb, line 70
def self.requires_prefix?

        return @requires_prefix unless @requires_prefix.nil?

        @requires_prefix = ::Pantheios::Services::Common::Console::Internal_::SHOULD_COLOURIZE_ ? :parts : false
end

Public Instance Methods

infer_stream(sev) click to toggle source

Overrideable method that determines which stream to write, based on a severity. This implementation always returns +$stderr+

Overrides must return an object that supports the +puts(String)+ method

# File lib/pantheios/services/coloured_console_log_service.rb, line 191
def infer_stream sev

        $stderr
end
log(sev, t, pref, msg) click to toggle source
# File lib/pantheios/services/coloured_console_log_service.rb, line 87
def log sev, t, pref, msg

        stm = infer_stream sev

        if requires_prefix?

                pref = pref.map do |part|

                        bg  =        Constants::Background
                        fg  =        Constants::Foreground

                        if part.respond_to?(:severity)

                                part = fg.bold part

                                case sev
                                when :violation

                                        part = bg.red part
                                        #part = fg.bright_magenta part
                                        part = fg.bright_yellow part
                                        part = fg.blinking part
                                when :alert

                                        part = bg.red part
                                        part = fg.bright_cyan part
                                        part = fg.blinking part
                                when :critical

                                        part = bg.red part
                                        part = fg.white part
                                when :failure

                                        part = bg.yellow part
                                        part = fg.red part
                                when :warning

                                        part = bg.yellow part
                                        part = fg.blue part
                                when :notice

                                        part = bg.dark_grey part
                                        part = fg.white part
                                when :informational

                                        part = bg.dark_grey part
                                        part = fg.light_grey part
                                when :debug0

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :debug1

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :debug2

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :debug3

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :debug4

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :debug5

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :trace

                                        part = bg.blue part
                                        part = fg.light_grey part
                                when :benchmark

                                        part = bg.black part
                                        part = fg.light_grey part
                                else

                                        ;
                                end
                        else

                                part = fg.dark_grey part
                        end

                        part
                end.join(', ')

                pref = '[' + pref + ']: '

                #pref = pref.map { |pp| pp.severity? ? map_sev_(sev) : sev }.join(
        end

        stm.puts "#{pref}#{msg}"
end
requires_prefix?() click to toggle source
# File lib/pantheios/services/coloured_console_log_service.rb, line 77
def requires_prefix?

        self.class.requires_prefix?
end
severity_logged?(severity) click to toggle source
# File lib/pantheios/services/coloured_console_log_service.rb, line 82
def severity_logged? severity

        true
end