Sha256: d2762dfaa829c3236ea6dd57feb822a32c956964ee7d0ac87ad09fa851a1c1d4

Contents?: true

Size: 1.43 KB

Versions: 59

Compression:

Stored size: 1.43 KB

Contents

# :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:

Version data entries

59 entries across 51 versions & 6 rubygems

Version Path
logging-2.4.0 examples/custom_log_levels.rb
logging-2.3.1 examples/custom_log_levels.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/custom_log_levels.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/custom_log_levels.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/custom_log_levels.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/custom_log_levels.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/custom_log_levels.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/custom_log_levels.rb
logging-2.3.0 examples/custom_log_levels.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/custom_log_levels.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/logging-2.2.2/examples/custom_log_levels.rb