Class: Log4r::EmailOutputter

Class Log4r::EmailOutputter |
In: | log4r/outputter/emailoutputter.rb
Parent: | Outputter

# EmailOutputter

This is an experimental class. It should work fine if Net:SMTP doesn't give you any problems. Just in case, create a logger named 'log4r' and give it an outputter to see the logging statements made by this class. If it fails to send email, it will set itself to OFF and stop logging.

In order to use it,

      require 'log4r/outputter/emailoutputter'

## SMTP Configuration

All arguments to Net::SMTP.start are supported. Pass them as hash parameters to `new`. The to field is specified as a comma-delimited list of emails (padded with \s* if desired).

An example:

      EmailOutputter.new 'myemail',
                         :server=>'localhost',
                         :port=>25,
                         :domain=>'somewhere.com',
                         :from=>'me@foo.bar',
                         :to=>'them@foo.bar, me@foo.bar, bozo@clown.net'

## LogEvent Buffer

This class has an internal LogEvent buffer to let you accumulate a bunch of log messages per email. Specify the size of the buffer with the hash parameter `buffsize`. The default is 100.

## Flush Me

When shutting down your program, you might want to call flush on this outputter to send the remaining LogEvents. Might as well flush everything while you're at it:

      Outputter.each_outputter {|o| o.flush}

## Format When?

You may choose to format the LogEvents as they come in or as the email is being composed. To do the former, specify a value of `true` to the hash parameter `formatfirst`. The default is to format during email composition.

## Immediate Notification

If you want certain log priorities to trigger an immediate email, set the hash parameter `immediate_at` to a string list of comma-delimited trigger levels (padded by \s* if desired).

## Example

A security logger sends email to several folks, buffering up to 25 log events and sending immediates on CRIT and WARN

      EmailOutputter.new 'security',
                         :to => 'bob@secure.net, frank@secure.net',
                         :buffsize => 25,
                         :immediate_at => 'WARN, CRIT'

## XML Configuration

See log4r/configurator.rb for details. Here's an example:

      <outputter name="security" type="EmailOutputter"
                 buffsize="25" level="ALL">
        <immediate_at>WARN, CRIT</immediate_at>
        <server>localhost</server>
        <from>me@secure.net</from>
        <to>
          bob@secure.net, frank@secure.net
        </to>
        ...
      </outputter>

Methods

flush, flush,

Attributes

[R] | :acct |
[R] | :authtype |
[R] | :domain |
[R] | :port |
[R] | :server |

Public Class methods

new(_name, hash={}) src

Public Instance methods

flush() src

send out an email with the current buffer