| Title: | Extra Appenders for 'lgr' |
|---|---|
| Description: | Additional appenders for the logging package 'lgr' that support logging to 'Elasticsearch', 'Dynatrace', 'AWSCloudWatchLog', databases, 'syslog', email- and push notifications, and more. |
| Authors: | Stefan Fleck [aut, cre] (ORCID: <https://orcid.org/0000-0003-3344-9851>), Jimmy Briggs [ctb, rev] (ORCID: <https://orcid.org/0000-0002-7489-8787>) |
| Maintainer: | Stefan Fleck <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.2.9000 |
| Built: | 2026-06-03 09:44:43 UTC |
| Source: | https://github.com/s-fleck/lgrextra |
Log to AWS CloudWatch Logs.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
By default, AppenderAWSCloudWatchLog writes each LogEvent which can be relatively slow.
To improve performance it is possible to tell
AppenderAWSCloudWatchLog to buffer db writes by setting buffer_size to something greater
than 0. This buffer is written to AWS CloudWatch whenever it is full
(buffer_size), whenever a LogEvent with a level of fatal or error is
encountered (flush_threshold), or when the Appender is garbage collected
(flush_on_exit), i.e. when you close the R session or shortly after you
remove the Appender object via rm().
An AppenderAWSCloudWatchLog is linked to an AWS Account using the
paws sdk package. If the
log group does not exist it is created either when the Appender is first
instantiated or (more likely) when the first LogEvent would be written to
that table.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderAWSCloudWatchLog
clientlog_group_nameThe name of the AWS CloudWatch log group.
log_stream_nameThe name of the log stream within the log_group_name.
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()new()
AppenderAWSCloudWatchLog$new( log_group_name, log_stream_name = paste(log_group_name, Sys.Date(), sep = "/"), log_group_retention_days = NULL, paws_config = list(), threshold = NA_integer_, layout = LayoutFormat$new(fmt = "%L: %m", colors = list()), buffer_size = 0, flush_threshold = "error", flush_on_exit = TRUE, flush_on_rotate = TRUE, should_flush = NULL, filters = NULL )
log_group_nameThe name of the AWS CloudWatch log group.
log_stream_nameThe name of the log stream within the log_group_name.
log_group_retention_daysThe number of days to retain the log events in the specified log group. AWS API Documentation
paws_configlist of paws config. Please see section https://www.paws-r-sdk.com/docs/set_service_parameter/
threshold, flush_threshold, layout, buffer_sizeset_client()
set paws.management cloudwatchlogs client
AppenderAWSCloudWatchLog$set_client(client)
client(paws.management::cloudwatchlogs) client.
AWS CloudWatch
set_log_group_name()
set log group name for AWS CloudWatch
AppenderAWSCloudWatchLog$set_log_group_name(log_group_name)
log_group_name(character) name of AWS CloudWatch
set_log_stream_name()
set log stream name within AWS CloudWatch log group
AppenderAWSCloudWatchLog$set_log_stream_name(log_stream_name)
log_stream_name(character) log stream name with AWS CloudWatch log group
set_log_group_retention_days()
set log group retention days for AWS CloudWatch Log Group.
AppenderAWSCloudWatchLog$set_log_group_retention_days(log_group_retention_days)
log_group_retention_daysThe number of days to retain the log events in the specified log group. AWS API Documentation
flush()
AppenderAWSCloudWatchLog$flush()
Other Appenders:
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
## Not run: library(lgrExtra) app <- AppenderAWSCloudWatchLog$new(log_group_name = "lgrExtra") lg <- lgr::get_logger("lgrExtra")$add_appender(app)$set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup ## End(Not run)## Not run: library(lgrExtra) app <- AppenderAWSCloudWatchLog$new(log_group_name = "lgrExtra") lg <- lgr::get_logger("lgrExtra")$add_appender(app)$set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup ## End(Not run)
Log to a database table with any DBI compatible backend. Please be
aware that AppenderDbi does not support case sensitive / quoted column
names, and you advised to only use all-lowercase names for
custom fields (see ... argument of lgr::LogEvent).
When appending to a database table all LogEvent values for which a column
exists in the target table will be appended, all others are ignored.
NOTE: AppenderDbi works reliable for most databases, but is still considered experimental, especially because the configuration is excessively complicated. Expect breaking changes to AppenderDbi in the future.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
By default, AppenderDbi writes each LogEvent directly to the target database
which can be relatively slow. To improve performance it is possible to tell
AppenderDbi to buffer db writes by setting buffer_size to something greater
than 0. This buffer is written to the database whenever it is full
(buffer_size), whenever a LogEvent with a level of fatal or error is
encountered (flush_threshold), or when the Appender is garbage collected
(flush_on_exit), i.e. when you close the R session or shortly after you
remove the Appender object via rm().
An AppenderDbi is linked to a database table via its table argument. If the
table does not exist it is created either when the Appender is first
instantiated or (more likely) when the first LogEvent would be written to
that table. Rather than to rely on this feature, it is recommended that you
create the target table first using an SQL CREATE TABLE statement as this
is safer and more flexible. See also LayoutDbi.
Layouts for relational database tables are tricky as they have very strict column types and further restrictions. On top of that implementation details vary between database backends.
To make setting up AppenderDbi as painless as possible, the helper function
select_dbi_layout() tries to automatically determine sensible LayoutDbi
settings based on conn and - if it exists in the database already -
table. If table does not exist in the database and you start logging, a
new table will be created with the col_types from layout.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderDbi
connclose_on_exitTRUE or FALSE. Close the Database connection
when the Logger is removed?
col_typesa named character vector providing information about the
column types in the database. How the column types are reported
depends on the database driver. For example, SQLite returns human
readable data types (character, double, ...) while IBM DB2 returns
numeric codes representing the data type.
tablea character scalar or a DBI::Id specifying the target
database table
table_namecharacter scalar. Like $table, but always returns a
character scalar
table_idDBI::Id. Like $table, but always returns a DBI::Id
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()new()
AppenderDbi$new( conn, table, threshold = NA_integer_, layout = select_dbi_layout(conn, table), close_on_exit = TRUE, buffer_size = 0, flush_threshold = "error", flush_on_exit = TRUE, flush_on_rotate = TRUE, should_flush = NULL, filters = NULL )
conn, tablesee section Fields
threshold, flush_threshold, layout, buffer_sizeset_close_on_exit()
AppenderDbi$set_close_on_exit(x)
set_conn()
AppenderDbi$set_conn(conn)
show()
AppenderDbi$show(threshold = NA_integer_, n = 20)
flush()
AppenderDbi$flush()
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
if (requireNamespace("RSQLite")){ app <- AppenderDbi$new( conn = DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:"), table = "log" ) lg <- lgr::get_logger("test/dbi")$ add_appender(app, "db")$ set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup }if (requireNamespace("RSQLite")){ app <- AppenderDbi$new( conn = DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:"), table = "log" ) lg <- lgr::get_logger("test/dbi")$ add_appender(app, "db")$ set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup }
Digests is an abstract class for report-like output that contain several log messages and a title; e.g. an E-mail containing the last 10 log messages before an error was encountered or a push notification.
Abstract classes, only exported for package developers.
Abstract classes cannot be instantiated with $new() and therefore
do not return anything. They are solely for developers that want to write
their own extension to lgr.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderDigest
subject_layoutA lgr::Layout used to format the last lgr::LogEvent in this Appenders buffer when it is flushed. The result will be used as the subject of the digest (for example, the E-mail subject).
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$flush()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()new()
AppenderDigest$new(...)
set_subject_layout()
AppenderDigest$set_subject_layout(layout)
lgr::LayoutFormat, lgr::LayoutGlue
Other abstract classes:
AppenderMail
Other Digest Appenders:
AppenderMail,
AppenderPushbullet,
AppenderSendmail
Log to Dynatrace via the Dynatrace log ingestion API.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderDynatrace
urla string url
api_keya string api_key. Also referred to as "Api Token"
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()new()
AppenderDynatrace$new( url, api_key, threshold = NA_integer_, layout = DynatraceLayout, buffer_size = 0, flush_threshold = "error", flush_on_exit = TRUE, flush_on_rotate = TRUE, should_flush = NULL, filters = NULL )
urlsee section Fields
threshold, flush_threshold, layout, buffer_sizeset_url()
AppenderDynatrace$set_url(url)
set_api_key()
AppenderDynatrace$set_api_key(api_key)
get_data()
Get log as data.frame: Not supported for Dynatrace
AppenderDynatrace$get_data(n = 20L, threshold = NA, result_type = "data.frame")
show()
Show log in console: Not supported for Dynatrace
AppenderDynatrace$show(threshold = NA_integer_, n = 20)
flush()
AppenderDynatrace$flush()
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
NOTE: Maturing; not yet fully documented but well tested in a production scenario
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderElasticSearch
connindextarget ElasticSearch index. May either be:
a character scalar, or
a function returning a character scalar
index_create_bodycharacter scalar json string (or NULL).
a function returning a character scalar json string (or NULL)
Optional settings,
mappings, aliases, etc... in case the target index has to be created
by the logger. See https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()new()
AppenderElasticSearch$new( conn, index, threshold = NA_integer_, layout = ElasticSearchLayout, index_create_body = NULL, buffer_size = 0, flush_threshold = "error", flush_on_exit = TRUE, flush_on_rotate = TRUE, should_flush = NULL, filters = NULL )
conn, indexsee section Fields
threshold, flush_threshold, layout, buffer_sizesee lgr::AppenderBuffer
A data data.frame. content of index
set_conn()
AppenderElasticSearch$set_conn(conn)
get_data()
AppenderElasticSearch$get_data( n = 20L, threshold = NA, result_type = "data.frame" )
ninteger scalar. Retrieve only the last n log entries that match
threshold
thresholdcharacter or integer scalar. The minimum log level
that should be displayed
result_typecharacter scalar. Any of:
data.frame
data.table (shortcut: dt)
list (unprocessed list with ElasticSearch metadata)
json (raw ElasticSearch JSON)
see result_type
show()
AppenderElasticSearch$show(threshold = NA_integer_, n = 20)
flush()
AppenderElasticSearch$flush()
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
Send mails via gmailr::gm_send_message(). This
Appender keeps an in-memory buffer like lgr::AppenderBuffer. If the buffer is
flushed, usually because an event of specified magnitude is encountered, all
buffered events are concatenated to a single message. The default behavior
is to push the last 30 log events in case a fatal event is encountered.
NOTE: This Appender requires that you set up google API authorization, please refer to the documentation of gmailr for details.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> lgrExtra::AppenderDigest -> lgrExtra::AppenderMail -> AppenderGmail
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()lgrExtra::AppenderDigest$set_subject_layout()lgrExtra::AppenderMail$format()lgrExtra::AppenderMail$set_bcc()lgrExtra::AppenderMail$set_cc()lgrExtra::AppenderMail$set_from()lgrExtra::AppenderMail$set_html()lgrExtra::AppenderMail$set_to()new()
see AppenderMail for details
AppenderGmail$new( to, threshold = NA_integer_, flush_threshold = "fatal", layout = LayoutFormat$new(fmt = "%L [%t] %m %f", timestamp_fmt = "%H:%M:%S"), subject_layout = LayoutFormat$new(fmt = "[LGR] %L: %m"), buffer_size = 30, from = get_user(), cc = NULL, bcc = NULL, html = FALSE, filters = NULL )
flush()
AppenderGmail$flush()
lgr::LayoutFormat, lgr::LayoutGlue
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderPool,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
Abstract classes, only exported for package developers.
Abstract classes cannot be instantiated with $new() and therefore
do not return anything. They are solely for developers that want to write
their own extension to lgr.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> lgrExtra::AppenderDigest -> AppenderMail
tocharacter vector. The email addresses of the recipient
fromcharacter vector. The email address of the sender
cccharacter vector. The email addresses of the cc-recipients (carbon copy)
bcccharacter vector. The email addresses of bcc-recipients (blind carbon copy)
htmllogical scalar. Send a html email message?
This does currently only format the log contents as monospace verbatim
text.
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$flush()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()lgrExtra::AppenderDigest$set_subject_layout()new()
AppenderMail$new(...)
set_to()
AppenderMail$set_to(x)
set_from()
AppenderMail$set_from(x)
set_cc()
AppenderMail$set_cc(x)
set_bcc()
AppenderMail$set_bcc(x)
set_html()
AppenderMail$set_html(x)
format()
AppenderMail$format(color = FALSE, ...)
Other abstract classes:
AppenderDigest
Other Digest Appenders:
AppenderDigest,
AppenderPushbullet,
AppenderSendmail
Log to a database table using a connection pool from the pool package.
This provides better performance and connection management compared to
direct DBI connections, especially for applications with concurrent users.
Like AppenderDbi, it does not support case sensitive / quoted column
names, and you are advised to only use all-lowercase names for
custom fields (see ... argument of lgr::LogEvent).
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
Using connection pools instead of direct DBI connections provides several advantages:
Connections are reused rather than created for each query
Connection management is automated (creation, validation, destruction)
Better handles concurrent requests in multi-user applications
Improves overall performance by reducing connection overhead
Like AppenderDbi, AppenderPool supports buffered logging by setting buffer_size
to something greater than 0. This buffer is written to the database whenever it is full
(buffer_size), whenever a LogEvent with a level of fatal or error is
encountered (flush_threshold), or when the Appender is garbage collected
(flush_on_exit).
An AppenderPool is linked to a database table via its table argument. If the
table does not exist it is created either when the Appender is first
instantiated or when the first LogEvent would be written to that table.
It is recommended to create the target table first using an SQL CREATE TABLE
statement for more control and safety.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderPool
poolclose_on_exitTRUE or FALSE. Close the pool connection
when the Logger is removed? Usually not necessary as pools manage their own lifecycle.
col_typesa named character vector providing information about the
column types in the database.
tablea character scalar or a DBI::Id specifying the target
database table
table_namecharacter scalar. Like $table, but always returns a
character scalar
table_idDBI::Id. Like $table, but always returns a DBI::Id
lgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()new()
AppenderPool$new( pool, table, threshold = NA_integer_, layout = select_dbi_layout(pool::poolCheckout(pool), table), close_on_exit = FALSE, buffer_size = 0, flush_threshold = "error", flush_on_exit = TRUE, flush_on_rotate = TRUE, should_flush = NULL, filters = NULL )
pool, tablesee section Fields
threshold, flush_threshold, layout, buffer_sizeset_close_on_exit()
AppenderPool$set_close_on_exit(x)
set_pool()
AppenderPool$set_pool(pool)
show()
AppenderPool$show(threshold = NA_integer_, n = 20)
flush()
AppenderPool$flush()
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPushbullet,
AppenderSendmail,
AppenderSyslog
if (requireNamespace("RSQLite") && requireNamespace("pool")){ pool <- pool::dbPool( drv = RSQLite::SQLite(), dbname = ":memory:" ) app <- AppenderPool$new( pool = pool, table = "log" ) lg <- lgr::get_logger("test/pool")$ add_appender(app, "db")$ set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup pool::poolClose(pool) }if (requireNamespace("RSQLite") && requireNamespace("pool")){ pool <- pool::dbPool( drv = RSQLite::SQLite(), dbname = ":memory:" ) app <- AppenderPool$new( pool = pool, table = "log" ) lg <- lgr::get_logger("test/pool")$ add_appender(app, "db")$ set_propagate(FALSE) lg$info("test") print(lg$appenders[[1]]$data) invisible(lg$config(NULL)) # cleanup pool::poolClose(pool) }
Send push notifications via Pushbullet. This
Appender keeps an in-memory buffer like lgr::AppenderBuffer. If the buffer is
flushed, usually because an event of specified magnitude is encountered, all
buffered events are concatenated to a single message that is sent to
RPushbullet::pbPost(). The default behavior is to push the last 7 log
events in case a fatal event is encountered.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> lgrExtra::AppenderDigest -> AppenderPushbullet
apikeyrecipientsemailchanneldeviceslgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$format()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()lgrExtra::AppenderDigest$set_subject_layout()new()
AppenderPushbullet$new(
threshold = NA_integer_,
flush_threshold = "fatal",
layout = LayoutFormat$new(fmt = "%K %t> %m %f", timestamp_fmt = "%H:%M:%S"),
subject_layout = LayoutFormat$new(fmt = "[LGR] %L: %m"),
buffer_size = 6,
recipients = NULL,
email = NULL,
channel = NULL,
devices = NULL,
apikey = getOption("rpushbullet.key"),
filters = NULL
)threshold, flush_threshold, layout, buffer_sizesubject_layoutA lgr::LayoutFormat object.
recipients, email, channel, devices, apikeyflush()
AppenderPushbullet$flush()
set_apikey()
AppenderPushbullet$set_apikey(x)
set_recipients()
AppenderPushbullet$set_recipients(x)
set_email()
AppenderPushbullet$set_email(x)
set_channel()
AppenderPushbullet$set_channel(x)
set_devices()
AppenderPushbullet$set_devices(x)
lgr::LayoutFormat, lgr::LayoutGlue
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderSendmail,
AppenderSyslog
Other Digest Appenders:
AppenderDigest,
AppenderMail,
AppenderSendmail
if (requireNamespace("RPushbullet") && !is.null(getOption("rpushbullet.key")) ){ app <- AppenderPushbullet$new() lg <- lgr::get_logger("test/dbi")$ add_appender(app, "pb")$ set_propagate(FALSE) lg$fatal("info") lg$fatal("test") invisible(lg$config(NULL)) }if (requireNamespace("RPushbullet") && !is.null(getOption("rpushbullet.key")) ){ app <- AppenderPushbullet$new() lg <- lgr::get_logger("test/dbi")$ add_appender(app, "pb")$ set_propagate(FALSE) lg$fatal("info") lg$fatal("test") invisible(lg$config(NULL)) }
Send mails via sendmailR::sendmail(), which requires that you have access
to an SMTP server that does not require authentication. This
Appender keeps an in-memory buffer like lgr::AppenderBuffer. If the buffer is
flushed, usually because an event of specified magnitude is encountered, all
buffered events are concatenated to a single message. The default behavior
is to push the last 30 log events in case a fatal event is encountered.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> lgrExtra::AppenderDigest -> lgrExtra::AppenderMail -> AppenderSendmail
controlheaderslgr::Filterable$add_filter()lgr::Filterable$filter()lgr::Filterable$remove_filter()lgr::Filterable$set_filters()lgr::Appender$set_layout()lgr::Appender$set_threshold()lgr::AppenderMemory$append()lgr::AppenderMemory$clear()lgr::AppenderMemory$set_buffer_size()lgr::AppenderMemory$set_flush_on_exit()lgr::AppenderMemory$set_flush_on_rotate()lgr::AppenderMemory$set_flush_threshold()lgr::AppenderMemory$set_should_flush()lgr::AppenderMemory$show()lgrExtra::AppenderDigest$set_subject_layout()lgrExtra::AppenderMail$format()lgrExtra::AppenderMail$set_bcc()lgrExtra::AppenderMail$set_cc()lgrExtra::AppenderMail$set_from()lgrExtra::AppenderMail$set_html()lgrExtra::AppenderMail$set_to()new()
see AppenderMail for details
AppenderSendmail$new( to, control, threshold = NA_integer_, flush_threshold = "fatal", layout = LayoutFormat$new(fmt = " %L [%t] %m %f", timestamp_fmt = "%H:%M:%S"), subject_layout = LayoutFormat$new(fmt = "[LGR] %L: %m"), buffer_size = 29, from = get_user(), cc = NULL, bcc = NULL, html = FALSE, headers = NULL, filters = NULL )
flush()
AppenderSendmail$flush()
set_control()
AppenderSendmail$set_control(x)
set_headers()
AppenderSendmail$set_headers(x)
The default Layout's fmt indents each log entry with 3 blanks. This
is a workaround so that Microsoft Outlook does not mess up the line breaks.
lgr::LayoutFormat, lgr::LayoutGlue
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSyslog
Other Digest Appenders:
AppenderDigest,
AppenderMail,
AppenderPushbullet
## Not run: lgr::AppenderSendmail$new( to = "[email protected]", control = list(smtpServer = "mail.ecorp.com"), from = "[email protected]" ) ## End(Not run) if (requireNamespace("sendmailR")){ # requires that you have access to an SMTP server lg <- lgr::get_logger("lgrExtra/test/mail")$ set_propagate(FALSE)$ add_appender(AppenderSendmail$new( from = "[email protected]", to = "[email protected]", control = list(smtpServer = "mail.somesmptserver.com") )) # cleanup invisible(lg$config(NULL)) }## Not run: lgr::AppenderSendmail$new( to = "[email protected]", control = list(smtpServer = "mail.ecorp.com"), from = "[email protected]" ) ## End(Not run) if (requireNamespace("sendmailR")){ # requires that you have access to an SMTP server lg <- lgr::get_logger("lgrExtra/test/mail")$ set_propagate(FALSE)$ add_appender(AppenderSendmail$new( from = "[email protected]", to = "[email protected]", control = list(smtpServer = "mail.somesmptserver.com") )) # cleanup invisible(lg$config(NULL)) }
An Appender that writes to the syslog on supported POSIX platforms. Requires the rsyslog package.
The $new() method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
lgr::Filterable -> lgr::Appender -> AppenderSyslog
syslog_levels.Either a named character vector or a function
mapping lgr lgr::log_levels to rsyslog log levels. See
$set_syslog_levels().
identifiercharacter scalar. A string identifying the process;
if NULL defaults to the logger name
syslog_levels.Either a named character vector or a function
mapping lgr lgr::log_levels to rsyslog log levels. See
$set_syslog_levels().
new()
AppenderSyslog$new(
identifier = NULL,
threshold = NA_integer_,
layout = LayoutFormat$new("%m"),
filters = NULL,
syslog_levels = c(CRITICAL = "fatal", ERR = "error", WARNING = "warn", INFO = "info",
DEBUG = "debug", DEBUG = "trace")
)append()
AppenderSyslog$append(event)
set_syslog_levels()
Define conversion between lgr and syslog log levels
AppenderSyslog$set_syslog_levels(x)
x a named character vector mapping whose names are log
levels as understood by rsyslog::syslog() and whose values are lgr log levels (either character or numeric)
a function that takes a vector of lgr log levels as input and
returns a character vector of log levels for rsyslog::syslog().
set_identifier()
Set a string to identify the process.
AppenderSyslog$set_identifier(x)
lgr::LayoutFormat, lgr::LayoutGlue
Other Appenders:
AppenderAWSCloudWatchLog,
AppenderDbi,
AppenderDynatrace,
AppenderElasticSearch,
AppenderGmail,
AppenderPool,
AppenderPushbullet,
AppenderSendmail
if (requireNamespace("rsyslog", quietly = TRUE) && Sys.info()[["sysname"]] == "Linux") { lg <- lgr::get_logger("rsyslog/test") lg$add_appender(AppenderSyslog$new(), "syslog") lg$info("A test message") print(system("journalctl -t 'rsyslog/test'")) invisible(lg$config(NULL)) # cleanup }if (requireNamespace("rsyslog", quietly = TRUE) && Sys.info()[["sysname"]] == "Linux") { lg <- lgr::get_logger("rsyslog/test") lg$add_appender(AppenderSyslog$new(), "syslog") lg$info("A test message") print(system("journalctl -t 'rsyslog/test'")) invisible(lg$config(NULL)) # cleanup }
Convert POSIXct to Unix Epoch milliseconds
as_unix_epoch_ms(x)as_unix_epoch_ms(x)
x |
a |
LayoutDbi can contain col_types that AppenderDbi can use to create new
database tables; however, it is safer and more flexible to set up the log
table up manually with an SQL CREATE TABLE statement instead.
The LayoutDbi parameters fmt, timestamp_fmt, colors and pad_levels
are only applied for for console output via the $show() method and do not
influence database inserts in any way. The inserts are pre-processed by
the methods $format_data(), $format_colnames and $format_tablenames.
It does not format
LogEvents directly, but their data.table representations (see
lgr::as.data.table.LogEvent), as well as column- and table names.
The $new() method returns an R6::R6 that inherits from
lgr::Layout and can used as a Layout by an lgr::Appender.
Different databases have different data types and features. Currently the
following LayoutDbi subclasses exist that deal with specific databases,
but this list is expected to grow as lgrExtra matures:
LayoutSqlite: For SQLite databases
LayoutPostgres: for Postgres databases
LayoutMySql: for MySQL databases
LayoutDb2: for DB2 databases
The utility function select_dbi_layout() tries returns the appropriate
Layout for a DBI connection, but this does not work for odbc and JDBC
connections where you have to specify the layout manually.
For creating custom DB-specific layouts it should usually be enough to create
an R6::R6 class that inherits from LayoutDbi and choosing different
defaults for $format_table_name, $format_colnames and $format_data.
lgr::Layout -> lgr::LayoutFormat -> LayoutDbi
format_table_namea function to format the table name before
inserting to the database. The function will be applied to the
$table_name before inserting into the database. For example some,
databases prefer all lowercase names, some uppercase. SQL updates
should be case-agnostic, but sadly in practice not all DBI backends
behave consistently in this regard.
format_colnamesa function to format the column names before
inserting to the database. The function will be applied to the column
names of the data frame to be inserted into the database.
format_dataa function to format the data before
inserting into the database. The function will be applied to the whole
data frame.
namesof the columns that contain data that has been serialized to JSON strings
col_typesa named character vector of column types supported by
the target database. If not NULL this is used by AppenderDbi or
similar Appenders to create a new database table on instantiation of
the Appender. If the target database table already exists, col_types
is not used.
namesof the columns that contain data that has been serialized to JSON strings
col_namescolumn names of the target table (the same as
names(lo$col_types))
new()
LayoutDbi$new(
col_types = c(level = "integer", timestamp = "timestamp", logger = "varchar(256)",
caller = "varchar(256)", msg = "varchar(2048)", rawMsg = "varchar(2048)"),
serialized_cols = NULL,
fmt = "%L [%t] %m %f",
timestamp_fmt = "%Y-%m-%d %H:%M:%S",
colors = getOption("lgr.colors", list()),
pad_levels = "right",
format_table_name = identity,
format_colnames = identity,
format_data = data.table::as.data.table
)set_col_types()
LayoutDbi$set_col_types(x)
set_serialized_cols()
LayoutDbi$set_serialized_cols(x)
sql_create_table()
LayoutDbi$sql_create_table(table)
toString()
LayoutDbi$toString()
clone()
The objects of this class are cloneable with this method.
LayoutDbi$clone(deep = FALSE)
deepWhether to make a deep clone.
select_dbi_layout(), DBI::DBI,
Other Layout:
LayoutElasticSearch
Similar to lgr::LayoutJson, but with some modifications to prepare data for ElasticSearch.
The $new() method returns an R6::R6 that inherits from
lgr::Layout and can used as a Layout by an lgr::Appender.
lgr::Layout -> LayoutElasticSearch
toJSON_argsa list of values passed on to jsonlite::toJSON()
transform_eventa function with a single argument event that
takes a lgr::LogEvent and returns a list.
new()
LayoutElasticSearch$new(
toJSON_args = list(auto_unbox = TRUE),
transform_event = function(event) get("values", event)
)format_event()
LayoutElasticSearch$format_event(event)
set_toJSON_args()
LayoutElasticSearch$set_toJSON_args(x)
set_transform_event()
LayoutElasticSearch$set_transform_event(x)
clone()
The objects of this class are cloneable with this method.
LayoutElasticSearch$clone(deep = FALSE)
deepWhether to make a deep clone.
Other Layout:
LayoutDbi
Selects an appropriate Layout for a database table based on a DBI connection and - if it already exists in the database - the table itself.
select_dbi_layout(conn, table, ...)select_dbi_layout(conn, table, ...)
conn |
|
table |
a |
... |
passed on to the appropriate |
Serializers are used by AppenderDbi to store multiple values in a single
text column in a Database table. Usually you just want to use the default
SerializerJson. Please not that AppenderDbi as well as Serializers
are still experimental.
a Serializer R6::R6 object for AppenderDbi.
clone()
The objects of this class are cloneable with this method.
Serializer$clone(deep = FALSE)
deepWhether to make a deep clone.
lgrExtra::Serializer -> SerializerJson
new()
SerializerJson$new(
cols = "*",
cols_exclude = c("level", "timestamp", "logger", "caller", "msg"),
col_filter = is.atomic,
max_nchar = 2048L,
auto_unbox = TRUE
)serialize()
SerializerJson$serialize(event)
clone()
The objects of this class are cloneable with this method.
SerializerJson$clone(deep = FALSE)
deepWhether to make a deep clone.
# The defaul Serializer for 'custom fields' columns SerializerJson$new()# The defaul Serializer for 'custom fields' columns SerializerJson$new()
Transforms a lgr::LogEvent object into a list suitable for Dynatrace ingestion.
transform_event_dynatrace(event) DynatraceLayouttransform_event_dynatrace(event) DynatraceLayout
event |
A lgr::LogEvent object. |
An object of class LayoutJson (inherits from Layout, R6) of length 17.
A list of key-value pairs ready to be serialized to JSON for Dynatrace.
https://docs.dynatrace.com/docs/discover-dynatrace/references/semantic-dictionary/fields#service
Transforms a lgr::LogEvent object into a list suitable for ElasticSearch ingestion.
transform_event_elasticsearch(event) ElasticSearchLayouttransform_event_elasticsearch(event) ElasticSearchLayout
event |
A lgr::LogEvent object. |
An object of class LayoutJson (inherits from Layout, R6) of length 17.
A list of key-value pairs ready to be serialized to JSON for ElasticSearch
https://www.elastic.co/docs/reference/ecs
Unserialize data frame columns that contain JSON
unpack_json_cols(x, cols) ## S3 method for class 'data.table' unpack_json_cols(x, cols) ## S3 method for class 'data.frame' unpack_json_cols(x, cols)unpack_json_cols(x, cols) ## S3 method for class 'data.table' unpack_json_cols(x, cols) ## S3 method for class 'data.frame' unpack_json_cols(x, cols)
x |
a |
cols |
|
a data.frame with additional columns expanded from the columns
containing JSON
x <- data.frame( name = "example data", fields = '{"letters":["a","b","c"], "LETTERS":["A","B","C"]}', stringsAsFactors = FALSE ) res <- unpack_json_cols(x, "fields") res res$letters[[1]]x <- data.frame( name = "example data", fields = '{"letters":["a","b","c"], "LETTERS":["A","B","C"]}', stringsAsFactors = FALSE ) res <- unpack_json_cols(x, "fields") res res$letters[[1]]