@@ -191,6 +191,71 @@ def self.appenders
191
191
Logger . processor . appenders
192
192
end
193
193
194
+ # Returns a new logging appender for use as a standalone destination for all log messages
195
+ # sent to this logging instance only.
196
+ #
197
+ # Useful to send log message to stdout or stderr only and not forward to any other appenders.
198
+ #
199
+ # If a block is supplied then it will be used to customize the format
200
+ # of the messages sent to that appender. See SemanticLogger::Logger.new for
201
+ # more information on custom formatters
202
+ #
203
+ # Notes:
204
+ # - Any log messages to this logger instance will not be forwarded to any other appenders.
205
+ # - Logging is performed in the current thread, unless `async: true` is specified.
206
+ #
207
+ # Parameters
208
+ # file_name: [String]
209
+ # File name to write log messages to.
210
+ #
211
+ # Or,
212
+ # io: [IO]
213
+ # An IO Stream to log to.
214
+ # For example $stdout, $stderr, etc.
215
+ #
216
+ # Or,
217
+ # appender: [Symbol]
218
+ # A symbol identifying the appender to create.
219
+ # For example:
220
+ # :bugsnag, :elasticsearch, :graylog, :http, :mongodb, :new_relic, :splunk_http, :syslog, :wrapper
221
+ #
222
+ # name: [String]
223
+ # Name to be used in log messages.
224
+ #
225
+ # level: [:trace | :debug | :info | :warn | :error | :fatal]
226
+ # Override the log level for this appender.
227
+ # Default: SemanticLogger.default_level
228
+ #
229
+ # formatter: [Symbol|Object|Proc]
230
+ # Any of the following symbol values: :default, :color, :json, :logfmt, etc...
231
+ # Or,
232
+ # An instance of a class that implements #call
233
+ # Or,
234
+ # A Proc to be used to format the output from this appender
235
+ # Default: :default
236
+ #
237
+ # filter: [Regexp|Proc]
238
+ # RegExp: Only include log messages where the class name matches the supplied.
239
+ # regular expression. All other messages will be ignored.
240
+ # Proc: Only include log messages where the supplied Proc returns true
241
+ # The Proc must return true or false.
242
+ #
243
+ # Examples:
244
+ #
245
+ # # Send all logging output to Standard Out (Screen)
246
+ # logger = SemanticLogger.appender(name: "MyClass", io: $stdout)
247
+ #
248
+ # # Only write to standard output and not forward to other appenders.
249
+ # logger.info "Hello World"
250
+ #
251
+ # # Send all logging output to a file
252
+ # SemanticLogger.add_appender(file_name: 'logfile.log')
253
+ def self . appender ( name : "SemanticLogger" , **args , &block )
254
+ appender = Appender . factory ( **args , &block )
255
+ appender . name = name
256
+ appender
257
+ end
258
+
194
259
# Flush all queued log entries disk, database, etc.
195
260
# All queued log messages are written and then each appender is flushed in turn.
196
261
def self . flush
0 commit comments