Class: ANSI::Logger

### Home Classes Methods

### In Files

- lib/ansi/logger.rb

### Parent

Logger

### Methods

- #ansicolor=
- #ansicolor?
- #debug
- #error
- #fatal
- #formatter
- #info
- #styles
- #warn

### Files

- COPYING.rdoc
- DEMO.rdoc
- HISTORY.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ANSI
- ANSI::BBCode
- ANSI::Chain
- ANSI::Code
- ANSI::Columns
- ANSI::Constants
- ANSI::Diff
- ANSI::HexDump
- ANSI::Logger
- ANSI::Mixin
- ANSI::ProgressBar
- ANSI::String
- ANSI::Table
- ANSI::Terminal
- Object
- String

No matching classes.

# ANSI::Logger

Extended variation of Ruby's standard Logger library that supports color output.

    log = ANSI::Logger.new

    log.formatter do |severity, timestamp, progname, msg|
      ANSI::Logger::SIMPLE_FORMAT % [severity, msg]
    end

### Constants

DETAILED_FORMAT
SIMPLE_FORMAT

  Some available logging formats.

### Public Instance Methods

ansicolor=(on) click to toggle source

    # File lib/ansi/logger.rb, line 50
    def ansicolor=(on)
      @logdev.ansicolor = on
    end

ansicolor?() click to toggle source

    # File lib/ansi/logger.rb, line 45
    def ansicolor?
      @logdev.ansicolor?
    end

debug(progname=nil, &block) click to toggle source

    # File lib/ansi/logger.rb, line 97
    def debug(progname=nil, &block)
      return unless debug?
      @logdev.ansicolor? ? debug_with_color{ super } : super
    end

error(progname=nil, &block) click to toggle source

    # File lib/ansi/logger.rb, line 103
    def error(progname=nil, &block)
      return unless error?
      @logdev.ansicolor? ? error_with_color{ super } : super
    end

fatal(progname=nil, &block) click to toggle source

    # File lib/ansi/logger.rb, line 109
    def fatal(progname=nil, &block)
      return unless error?
      @logdev.ansicolor? ? fatal_with_color{ super } : super
    end

formatter(&block) click to toggle source

Dictate the way in which this logger should format the messages it displays. This method requires a block. The block should return formatted strings given severity, timestamp, progname and msg.

### Example

    logger = ANSI::Logger.new

    logger.formatter do |severity, timestamp, progname, msg|
      "#{progname}@#{timestamp} - #{severity}::#{msg}"
    end

    # File lib/ansi/logger.rb, line 67
    def formatter(&block)
      self.formatter = block if block
      super
    end

info(progname=nil, &block) click to toggle source

    # File lib/ansi/logger.rb, line 85
    def info(progname=nil, &block)
      return unless info?
      @logdev.ansicolor? ? info_with_color{ super } : super
    end

styles(options=nil) click to toggle source

    # File lib/ansi/logger.rb, line 72
    def styles(options=nil)
      @styles ||= {
        :info  => [],
        :warn  => [:yellow],
        :debug => [:cyan],
        :error => [:red],
        :fatal => [:bold, :red]
      }
      @styles.merge!(options) if options
      @styles
    end

warn(progname=nil, &block) click to toggle source

    # File lib/ansi/logger.rb, line 91
    def warn(progname=nil, &block)
      return unless warn?
      @logdev.ansicolor? ? warn_with_color{ super } : super
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.