class SemanticLogger::Appender::Rabbitmq
Public Class Methods
new(queue_name: "semantic_logger", rabbitmq_host: nil, metrics: false, **args, &block)
click to toggle source
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 messages where the class name matches the supplied. regular expression. All other messages will be ignored. Proc: Only include log messages where the supplied Proc returns true The Proc must return true or false. host: [String] Name of this host to appear in log messages. Default: SemanticLogger.host application: [String] Name of this application to appear in log messages. 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
Calls superclass method
SemanticLogger::Subscriber::new
# 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
Public Instance Methods
close()
click to toggle source
# File lib/semantic_logger/appender/rabbitmq.rb, line 95 def close @channel&.close @channel = nil @connection&.close @connection = nil end
default_formatter()
click to toggle source
Use JSON Formatter by default.
# File lib/semantic_logger/appender/rabbitmq.rb, line 111 def default_formatter SemanticLogger::Formatters::Json.new end
flush()
click to toggle source
# File lib/semantic_logger/appender/rabbitmq.rb, line 106 def flush # NOOP end
log(log)
click to toggle source
# File lib/semantic_logger/appender/rabbitmq.rb, line 102 def log(log) queue.publish(formatter.call(log, self)) end
queue()
click to toggle source
# File lib/semantic_logger/appender/rabbitmq.rb, line 115 def queue @queue ||= @channel.queue(@queue_name) end
reopen()
click to toggle source
# File lib/semantic_logger/appender/rabbitmq.rb, line 89 def reopen @connection = Bunny.new(@rabbitmq_args) @connection.start @channel = @connection.create_channel end