Class: Log4Ruby::ConsoleAppender

Inherits:
StreamAppender show all
Defined in:
lib/log4ruby/appenders/console_appender.rb

Overview

Sends console messages to either stdout or stderr.

Constant Summary collapse

TARGETS =
{:stdout => $stdout, :stderr => $stderr}

Instance Attribute Summary

Attributes inherited from Appender

#formatter

Instance Method Summary collapse

Methods inherited from StreamAppender

#close, #footer, #header

Methods inherited from Appender

#close, #closed?, #process_log

Constructor Details

#initialize(level, options = {}) ⇒ ConsoleAppender

New console appender.

Parameters:

  • level (Log4Ruby::Level)

    the threshold level for the appender.

  • options (Hash) (defaults to: {})

    configuration options. Supported keys are: :formatter - the formatter this appender should use. Uses the DefaultFormatter if not specified. :target - the target stream to use (:stdout or :stderr). Default is :stdout :colorize - true to color the content printed to the console. Default is false.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
# File 'lib/log4ruby/appenders/console_appender.rb', line 21

def initialize(level, options = {})
  target = get_option(options, :target, false, :stdout)
  raise ArgumentError.new("Invalid target '#{target}'. Must be either 'stdout' or 'stderr'.") unless TARGETS.has_key?(target)

  set_option(options, :stream, TARGETS[target], true)
  super(level, options)

  @colorize = get_option(options, :colorize, false, false)
  register_default_colors if @colorize
end

Instance Method Details

#register_color(level, color_details) ⇒ Object

Registers a color for a particular level. Does nothing if the colorize flag was false.

Parameters:

  • level (Log4Ruby::Level)

    the level to register the color for.

  • color_details (Array)

    the details of the color. An array with the attributes, foreground and background colours.



36
37
38
39
# File 'lib/log4ruby/appenders/console_appender.rb', line 36

def register_color(level, color_details)
  return if @colors.nil?
  @colors[level] = color_details
end