Skip to content

Commit

Permalink
New method to return standalone
Browse files Browse the repository at this point in the history
appender instance
  • Loading branch information
reidmorrison committed Dec 4, 2024
1 parent 05a00e1 commit 493ab6c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ gem "bugsnag"
# [optional] Rabbitmq appender
gem "bunny"
# [optional] Elasticsearch appender
# 7.14 has a breaking API change.
gem "elasticsearch", "~>7.13.0"
gem "elasticsearch"
# [optional] Graylog appender
gem "gelf"
# [optional] Honeybadger appender
Expand Down
65 changes: 65 additions & 0 deletions lib/semantic_logger/semantic_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,71 @@ def self.appenders
Logger.processor.appenders
end

# Returns a new logging appender for use as a standalone destination for all log messages
# sent to this logging instance only.
#
# Useful to send log message to stdout or stderr only and not forward to any other appenders.
#
# If a block is supplied then it will be used to customize the format
# of the messages sent to that appender. See SemanticLogger::Logger.new for
# more information on custom formatters
#
# Notes:
# - Any log messages to this logger instance will not be forwarded to any other appenders.
# - Logging is performed in the current thread, unless `async: true` is specified.
#
# Parameters
# file_name: [String]
# File name to write log messages to.
#
# Or,
# io: [IO]
# An IO Stream to log to.
# For example $stdout, $stderr, etc.
#
# Or,
# appender: [Symbol]
# A symbol identifying the appender to create.
# For example:
# :bugsnag, :elasticsearch, :graylog, :http, :mongodb, :new_relic, :splunk_http, :syslog, :wrapper
#
# name: [String]
# Name to be used in log messages.
#
# level: [:trace | :debug | :info | :warn | :error | :fatal]
# Override the log level for this appender.
# Default: SemanticLogger.default_level
#
# formatter: [Symbol|Object|Proc]
# Any of the following symbol values: :default, :color, :json, :logfmt, etc...
# Or,
# An instance of a class that implements #call
# Or,
# A Proc to be used to format the output from this appender
# Default: :default
#
# 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.
#
# Examples:
#
# # Send all logging output to Standard Out (Screen)
# logger = SemanticLogger.appender(name: "MyClass", io: $stdout)
#
# # Only write to standard output and not forward to other appenders.
# logger.info "Hello World"
#
# # Send all logging output to a file
# SemanticLogger.add_appender(file_name: 'logfile.log')
def self.appender(name: "SemanticLogger", **args, &block)
appender = Appender.factory(**args, &block)
appender.name = name
appender
end

# Flush all queued log entries disk, database, etc.
# All queued log messages are written and then each appender is flushed in turn.
def self.flush
Expand Down

0 comments on commit 493ab6c

Please sign in to comment.