Class: Logplex::Publisher
- Inherits:
-
Object
- Object
- Logplex::Publisher
- Defined in:
- lib/logplex/publisher.rb
Constant Summary collapse
- PUBLISH_ERRORS =
[Excon::Errors::InternalServerError, Excon::Errors::Unauthorized, Timeout::Error].freeze
Instance Method Summary collapse
-
#initialize(logplex_url = nil) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(messages, opts = {}) ⇒ Object
Constructor Details
#initialize(logplex_url = nil) ⇒ Publisher
Returns a new instance of Publisher.
12 13 14 15 |
# File 'lib/logplex/publisher.rb', line 12 def initialize(logplex_url = nil) @logplex_url = logplex_url || Logplex.configuration.logplex_url @token = URI(@logplex_url).password || Logplex.configuration.app_name end |
Instance Method Details
#publish(messages, opts = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logplex/publisher.rb', line 17 def publish(, opts={}) = .dup unless .is_a? Array = [] end .map! { |m| Message.new(m, { app_name: @token }.merge(opts)) } .each(&:validate) if .inject(true) { |accum, m| m.valid? } begin Timeout.timeout(Logplex.configuration.publish_timeout) do api_post(.map(&:syslog_frame).join(''), .length) true end rescue *PUBLISH_ERRORS false end end end |