Log to AWS CloudWatch Logs
AppenderAWSCloudWatchLog.Rd
Log to AWS CloudWatch Logs.
Value
The $new()
method returns an R6::R6 that inherits from
lgr::Appender and can be uses as an appender by a lgr::Logger.
Buffered Logging
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()
.
Creating a New Appender
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.
See also
Other Appenders:
AppenderDbi
,
AppenderDynatrace
,
AppenderElasticSearch
,
AppenderGmail
,
AppenderPool
,
AppenderPushbullet
,
AppenderSendmail
,
AppenderSyslog
Super classes
lgr::Filterable
-> lgr::Appender
-> lgr::AppenderMemory
-> AppenderAWSCloudWatchLog
Active bindings
client
log_group_name
The name of the AWS CloudWatch log group.
log_stream_name
The name of the log stream within the
log_group_name
.
Methods
Inherited methods
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()
Method new()
Usage
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
)
Arguments
log_group_name
The name of the AWS CloudWatch log group.
log_stream_name
The name of the log stream within the
log_group_name
.log_group_retention_days
The number of days to retain the log events in the specified log group. AWS API Documentation
paws_config
list of paws config. Please see section https://www.paws-r-sdk.com/docs/set_service_parameter/
threshold, flush_threshold, layout, buffer_size
Method set_log_group_retention_days()
set log group retention days for AWS CloudWatch Log Group.
Arguments
log_group_retention_days
The number of days to retain the log events in the specified log group. AWS API Documentation
Method flush()
Examples
if (FALSE) { # \dontrun{
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
} # }