Class: Extlib::Logger

### Home Classes Methods

### In Files

- lib/extlib/logger.rb

### Parent

Object

### Methods

- ::new
- #<<
- #close
- #flush
- #push
- #set_log

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Extlib
- Extlib::Assertions
- Extlib::ByteArray
- Extlib::Hook
- Extlib::Hook::ClassMethods
- Extlib::Inflection
- Extlib::LocalObjectSpace
- Extlib::Logger
- Extlib::Pooling
- Extlib::Pooling::InvalidResourceError
- Extlib::Pooling::Pool
- Extlib::SimpleSet
- Gem
- Gem::SourceIndex
- Gem::Specification
- LazyModule
- LazyModule::ClassMethods
- Array
- Class
- DateTime
- Dictionary
- FalseClass
- Hash
- LazyArray
- Mash
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- Pathname
- REXMLUtilityNode
- String
- Struct
- Symbol
- Time
- ToHashParser
- TrueClass
- VirtualFile

No matching classes.

# Extlib::Logger

### Constants

Levels

  #### Notes

  Ruby (standard) logger levels:

  :fatal | An unhandleable error that results in a program crash
  :error | A handleable error condition
  :warn | A warning
  :info | generic (useful) information about system operation
  :debug | low-level information for developers

### Attributes

auto_flush[RW]
buffer[R]
delimiter[RW]
init_args[R]
level[RW]
log[R]

### Public Class Methods

new(*args) click to toggle source

To initialize the logger you create a new object, proxies to set_log.

#### Parameters

*args | Arguments to create the log from. See set_logs for specifics.

    # File lib/extlib/logger.rb, line 93
    def initialize(*args)
      @init_args = args
      set_log(*args)
    end

### Public Instance Methods

<<(string = nil) click to toggle source

Appends a message to the log. The methods yield to an optional block and the output of this block will be appended to the message.

#### Parameters

string<String> | The message to be logged. Defaults to nil.

#### Returns

String | The resulting message added to the log file.

    # File lib/extlib/logger.rb, line 144
    def <<(string = nil)
      message = ""
      message << delimiter
      message << string if string
      message << "\n" unless message[-1] == \n\
      @buffer << message
      flush if @auto_flush

      message
    end

Also aliased as: push
close() click to toggle source

Close and remove the current log object.

    # File lib/extlib/logger.rb, line 130
    def close
      flush
      @log.close if @log.respond_to?(:close) && !@log.tty?
      @log = nil
    end

flush() click to toggle source

Flush the entire buffer to the log object.

    # File lib/extlib/logger.rb, line 124
    def flush
      return unless @buffer.size > 0
      @log.write(@buffer.slice!(0..-1).join)
    end

push(string = nil) click to toggle source
Alias for: <<
set_log(log, log_level = nil, delimiter = " ~ ", auto_flush = false) click to toggle source

Replaces an existing logger with a new one.

#### Parameters

log<IO, String> | Either an IO object or a name of a logfile.
log_level<~to_sym> | The log level from, e.g. :fatal or :info. Defaults to :error in the production environment and :debug otherwise.
delimiter<String> | Delimiter to use between message sections. Defaults to " ~ ".
auto_flush<Boolean> | Whether the log should automatically flush after new messages are added. Defaults to false.

    # File lib/extlib/logger.rb, line 110
    def set_log(log, log_level = nil, delimiter = " ~ ", auto_flush = false)
      if log_level && Levels[log_level.to_sym]
        @level = Levels[log_level.to_sym]
      else
        @level = Levels[:debug]
      end
      @buffer     = []
      @delimiter  = delimiter
      @auto_flush = auto_flush

      initialize_log(log)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.