class SemanticLogger::Appender::Rabbitmq
def close
def close @channel&.close @channel = nil @connection&.close @connection = nil end
def default_formatter
def default_formatter SemanticLogger::Formatters::Json.new end
def flush
def flush # NOOP end
def initialize(queue_name: "semantic_logger", rabbitmq_host: nil,
Default: nil
Password for AMQP connection
password: [String]
Default: nil
Username for AMQP connection
username: [String]
Default: localhost
been remapped to avoid conflicting with SemanticLogger's :host param.
Host for AMQP connection. in Bunny this is called :host but here it has
rabbitmq_host: [String]
RabbitMQ Parameters:
Default: true
Also send metrics only events to rabbitmq.
metrics: [Boolean]
Default: SemanticLogger.application
Name of this application to appear in log messages.
application: [String]
Default: SemanticLogger.host
Name of this host to appear in log messages.
host: [String]
The Proc must return true or false.
Proc: Only include log messages where the supplied Proc returns true
regular expression. All other messages will be ignored.
RegExp: Only include log messages where the class name matches the supplied.
filter: [Regexp|Proc]
Default: :json (See: #call)
the output from this appender
An instance of a class that implements #call, or a Proc to be used to format
formatter: [Object|Proc|Symbol|Hash]
Default: SemanticLogger.default_level
Override the log level for this appender.
level: [:trace | :debug | :info | :warn | :error | :fatal]
Default: semantic_logger
This will be a queue bound to AMQP Default exchange
Name of RabbitMQ queue where to stream logs to.
queue_name: [String]
Parameters:
Create RabbitMQ appender using Bunny gem
def initialize(queue_name: "semantic_logger", rabbitmq_host: nil, level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: true, **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, environment: environment, host: host, metrics: metrics, &block) reopen end
def log(log)
def log(log) queue.publish(formatter.call(log, self)) end
def queue
def queue @queue ||= @channel.queue(@queue_name) end
def reopen
def reopen @connection = Bunny.new(@rabbitmq_args) @connection.start @channel = @connection.create_channel end