flog.appender: Manage appenders for loggers

Description Arguments Usage Details Value Author(s) See Also Examples

Description

Provides functions for adding and removing appenders.

Arguments

...

Used internally by lambda.r

Usage

# Get the appender for the given logger
flog.appender(name) %::% character : Function
flog.appender(name='ROOT')

# Set the appender for the given logger
flog.appender(fn, name='ROOT')

# Print log messages to the console
appender.console()

# Write log messages to a file
appender.file(file)

# Write log messages to a dynamically-named file
appender.file2(format)

# Write log messages to console and a file
appender.tee(file)

# Write log messages to a Graylog2 HTTP GELF endpoint
appender.graylog(server, port)

# Write log message to syslog. Arguments are passed on to open_syslog.
appender.syslog(identifier, ...)

# Special meta appender that prints only when the internal counter mod n = 0
appender.modulo(n, appender=appender.console())

Details

Appenders do the actual work of writing log messages to some target. To use an appender in a logger, you must register it to a given logger. Use flog.appender to both access and set appenders.

The ROOT logger by default uses appender.console.

appender.console is a function that writes to the console. No additional arguments are necessary when registering the appender via flog.appender.

appender.file writes to a file, so you must pass an additional file argument to the function. To change the file name, just call flog.appender(appender.file(file)) again with a new file name.

appender.file2 is similar, but the filename is dynamically determined at runtime. It may include most of the same tokens as layout.format (all except "~m", the message itself). This allows, for instance, having separate logfiles for each log level.

To use your own appender create a function that takes a single argument, which represents the log message. You need to pass a function reference to flog.appender.

appender.tee writes to both the console and file.

appender.graylog writes to a Graylog2 HTTP GELF endpoint.

appender.syslog writes to the POSIX system logger.

appender.modulo is a meta appender. It calls appender every n times.

Value

When getting the appender, flog.appender returns the appender function. When setting an appender, flog.appender has no return value.

Author(s)

Brian Lee Yung Rowe

See Also

flog.logger flog.layout

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
flog.appender(appender.console(), name='my.logger')

# Set an appender to the logger named 'my.package'. Any log operations from
# this package will now use this appender.
flog.appender(appender.file('my.package.out'), 'my.package')

# Set an appender to a file named using the message level and calling function.
# Also tee the messages to the console.
flog.appender(appender.file2('~l-~f.log', console = TRUE))

## End(Not run)

zatonovo/futile.logger documentation built on Feb. 23, 2022, 10:18 p.m.