Class: Logging::Appenders::Email

Inherits:
Logging::Appender show all
Includes:
Buffering
Defined in:
lib/logging/appenders/email.rb

Constant Summary

Constants included from Buffering

Buffering::DEFAULT_BUFFER_SIZE

Instance Attribute Summary collapse

Attributes included from Buffering

#auto_flushing, #buffer, #flush_period

Attributes inherited from Logging::Appender

#layout, #level, #name

Instance Method Summary collapse

Methods included from Buffering

#close, #flush, #immediate_at=, #reopen

Methods inherited from Logging::Appender

#<<, #append, #close, #closed?, #flush, #inspect, #reopen

Constructor Details

#initialize(name, opts = {}) ⇒ Email

TODO: make the from/to fields modifiable

possibly the subject, too

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/logging/appenders/email.rb', line 20

def initialize( name, opts = {} )
  super(name, opts)

  af = opts.getopt(:buffsize) ||
       opts.getopt(:buffer_size) ||
       100
  configure_buffering({:auto_flushing => af}.merge(opts))

  # get the SMTP parameters
  @from = opts.getopt(:from)
  raise ArgumentError, 'Must specify from address' if @from.nil?

  @to = opts.getopt(:to, '').split(',')
  raise ArgumentError, 'Must specify recipients' if @to.empty?

  @server   = opts.getopt :server, 'localhost'
  @port     = opts.getopt :port, 25, :as => Integer
  @domain   = opts.getopt(:domain, ENV['HOSTNAME']) || 'localhost.localdomain'
  @acct     = opts.getopt :acct
  @passwd   = opts.getopt :passwd
  @authtype = opts.getopt :authtype, :cram_md5, :as => Symbol
  @subject  = opts.getopt :subject, "Message of #{$0}"
  @params   = [@server, @port, @domain, @acct, @passwd, @authtype]
end

Instance Attribute Details

#acctObject (readonly)

Returns the value of attribute acct.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def acct
  @acct
end

#authtypeObject (readonly)

Returns the value of attribute authtype.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def authtype
  @authtype
end

#domainObject (readonly)

Returns the value of attribute domain.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def domain
  @domain
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def server
  @server
end

#subjectObject (readonly)

Returns the value of attribute subject.



15
16
17
# File 'lib/logging/appenders/email.rb', line 15

def subject
  @subject
end