Class: Logging::Appenders::Email
- Inherits:
-
Logging::Appender
- Object
- Logging::Appender
- Logging::Appenders::Email
- Defined in:
- lib/gems/logging-0.9.4/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?, #inspect, remove, stderr, stdout
Constructor Details
#initialize(name, opts = {}) ⇒ Email
Returns a new instance of Email.
16 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 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 16 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.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 def acct @acct end |
#authtype ⇒ Object (readonly)
Returns the value of attribute authtype.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 def authtype @authtype end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 def domain @domain end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 def server @server end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
14 15 16 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 14 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.
64 65 66 67 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 64 def close( = true ) super flush end |
#flush ⇒ Object
call-seq:
flush
Create and send an email containing the current message buffer.
53 54 55 56 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 53 def flush sync { send_mail } self end |
#queued_messages ⇒ Object
cal-seq:
=> integer
Returns the number of messages in the buffer.
74 75 76 |
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/email.rb', line 74 def @buff.length end |