1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# :stopdoc:
#
# It's useful to define custom log levels that denote success, or otherwise
# meaningful events that happen to not be negative (more than 50% of the
# levels are given to warn, error, fail - quite a pessimistic view of one's
# application's chances of success, no? ;-) )
#
# Here, we define two new levels, 'happy' and 'success' and make them soothing
# colours.
#
require 'logging'
# https://github.com/TwP/logging/blob/master/lib/logging.rb#L250-285
# The levels run from lowest level to highest level.
Logging.init :debug, :info, :happy, :warn, :success, :error, :fatal
Logging.color_scheme( 'soothing_ish',
:levels => {
:info => :cyan,
:happy => :green,
:warn => :yellow,
:success => [:blue],
:error => :red,
:fatal => [:white, :on_red]
},
:date => :cyan,
:logger => :cyan,
:message => :orange
)
Logging.appenders.stdout(
'stdout',
:layout => Logging.layouts.pattern(
:pattern => '[%d] %-7l %c: %m\n',
:color_scheme => 'soothing_ish'
)
)
log = Logging.logger['Soothing::Colors']
log.add_appenders 'stdout'
log.level = :debug
log.debug 'a very nice little debug message'
log.info 'things are operating nominally'
log.happy 'What a beautiful day'
log.warn 'this is your last warning'
log.success 'I am INWEENCIBLE!!'
log.error StandardError.new('something went horribly wrong')
log.fatal 'I Die!'
# :startdoc:
|