Class: Logging::Appenders::Email
- Inherits:
-
Logging::Appender
- Object
- Logging::Appender
- Logging::Appenders::Email
- Defined in:
- lib/logging/appenders/email.rb
Instance Attribute Summary collapse
-
#acct ⇒ Object
readonly
Returns the value of attribute acct.
-
#authtype ⇒ Object
readonly
Returns the value of attribute authtype.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Attributes inherited from Logging::Appender
Instance Method Summary collapse
-
#close(footer = true) ⇒ Object
call-seq: close( footer = true ).
-
#flush ⇒ Object
call-seq: flush.
-
#initialize(name, opts = {}) ⇒ Email
constructor
A new instance of Email.
-
#queued_messages ⇒ Object
cal-seq: queued_messages => integer.
Methods inherited from Logging::Appender
#<<, [], []=, #append, #closed?, remove, stderr, stdout
Constructor Details
#initialize(name, opts = {}) ⇒ Email
Returns a new instance of Email.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/logging/appenders/email.rb', line 17 def initialize( name, opts = {} ) super(name, opts) @buff = [] @buffsize = opts.getopt :buffsize, 100, :as => Integer # get the immediate levels -- no buffering occurs at these levels, and # an e-mail is sent as soon as possible @immediate = [] opts.getopt(:immediate_at, '').split(',').each do |lvl| num = ::Logging.level_num(lvl.strip) next if num.nil? @immediate[num] = true end # 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
#acct ⇒ Object (readonly)
Returns the value of attribute acct.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def acct @acct end |
#authtype ⇒ Object (readonly)
Returns the value of attribute authtype.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def authtype @authtype end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def domain @domain end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def server @server end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
15 16 17 |
# File 'lib/logging/appenders/email.rb', line 15 def subject @subject end |
Instance Method Details
#close(footer = true) ⇒ Object
call-seq:
close( = true )
Close the e-mail appender and then flush the message buffer. This will ensure that a final e-mail is sent with any remaining messages.
65 66 67 68 |
# File 'lib/logging/appenders/email.rb', line 65 def close( = true ) super flush end |
#flush ⇒ Object
call-seq:
flush
Create and send an email containing the current message buffer.
54 55 56 57 |
# File 'lib/logging/appenders/email.rb', line 54 def flush sync { send_mail } self end |
#queued_messages ⇒ Object
cal-seq:
=> integer
Returns the number of messages in the buffer.
75 76 77 |
# File 'lib/logging/appenders/email.rb', line 75 def @buff.length end |