Class: SemanticLogger::Appender::Rabbitmq
- Inherits:
-
Subscriber
- Object
- Base
- Subscriber
- SemanticLogger::Appender::Rabbitmq
- Defined in:
- lib/semantic_logger/appender/rabbitmq.rb
Instance Attribute Summary
Attributes inherited from Subscriber
#application, #environment, #formatter, #host, #logger, #metrics
Attributes inherited from Base
Instance Method Summary collapse
- #close ⇒ Object
-
#default_formatter ⇒ Object
Use JSON Formatter by default.
- #flush ⇒ Object
-
#initialize(queue_name: "semantic_logger", rabbitmq_host: nil, metrics: false, **args, &block) ⇒ Rabbitmq
constructor
Create RabbitMQ appender using Bunny gem.
- #log(log) ⇒ Object
- #queue ⇒ Object
- #reopen ⇒ Object
Methods inherited from Subscriber
#console_output?, #level, #should_log?
Methods inherited from Base
#backtrace, #fast_tag, #level, #level=, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags
Constructor Details
#initialize(queue_name: "semantic_logger", rabbitmq_host: nil, metrics: false, **args, &block) ⇒ Rabbitmq
Create RabbitMQ appender using Bunny gem
Parameters:
queue_name: [String]
Name of RabbitMQ queue where to stream logs to.
This will be a queue bound to AMQP Default exchange
Default: semantic_logger
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender.
Default: SemanticLogger.default_level
formatter: [Object|Proc|Symbol|Hash]
An instance of a class that implements #call, or a Proc to be used to format
the output from this appender
Default: :json (See: #call)
filter: [Regexp|Proc]
RegExp: Only include log where the class name matches the supplied.
regular expression. All other will be ignored.
Proc: Only include log where the supplied Proc returns true
The Proc must return true or false.
host: [String]
Name of this host to appear in log .
Default: SemanticLogger.host
application: [String]
Name of this application to appear in log .
Default: SemanticLogger.application
RabbitMQ Parameters:
rabbitmq_host: [String]
Host for AMQP connection. in Bunny this is called :host but here it has
been remapped to avoid conflicting with SemanticLogger's :host param.
Default: localhost
username: [String]
Username for AMQP connection
Default: nil
password: [String]
Password for AMQP connection
Default: nil
more parameters supported by Bunny: http://rubybunny.info/articles/connecting.html
79 80 81 82 83 84 85 86 87 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 79 def initialize(queue_name: "semantic_logger", rabbitmq_host: nil, metrics: false, **args, &block) @queue_name = queue_name @rabbitmq_args = args.dup @rabbitmq_args[:host] = rabbitmq_host @rabbitmq_args[:logger] = logger super(level: level, formatter: formatter, filter: filter, application: application, host: host, metrics: metrics, &block) reopen end |
Instance Method Details
#close ⇒ Object
95 96 97 98 99 100 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 95 def close @channel&.close @channel = nil @connection&.close @connection = nil end |
#default_formatter ⇒ Object
Use JSON Formatter by default.
111 112 113 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 111 def default_formatter SemanticLogger::Formatters::Json.new end |
#flush ⇒ Object
106 107 108 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 106 def flush # NOOP end |
#log(log) ⇒ Object
102 103 104 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 102 def log(log) queue.publish(formatter.call(log, self)) end |
#queue ⇒ Object
115 116 117 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 115 def queue @queue ||= @channel.queue(@queue_name) end |
#reopen ⇒ Object
89 90 91 92 93 |
# File 'lib/semantic_logger/appender/rabbitmq.rb', line 89 def reopen @connection = Bunny.new(@rabbitmq_args) @connection.start @channel = @connection.create_channel end |