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.

Super classes

lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> AppenderAWSCloudWatchLog

Active bindings

client

a paws.management cloudwatchlogs 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


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

see lgr::AppenderBuffer


Method set_client()

set paws.management cloudwatchlogs client

Usage

AppenderAWSCloudWatchLog$set_client(client)

Arguments


Method set_log_group_name()

set log group name for AWS CloudWatch

Usage

AppenderAWSCloudWatchLog$set_log_group_name(log_group_name)

Arguments

log_group_name

(character) name of AWS CloudWatch


Method set_log_stream_name()

set log stream name within AWS CloudWatch log group

Usage

AppenderAWSCloudWatchLog$set_log_stream_name(log_stream_name)

Arguments

log_stream_name

(character) log stream name with AWS CloudWatch log group


Method set_log_group_retention_days()

set log group retention days for AWS CloudWatch Log Group.

Usage

AppenderAWSCloudWatchLog$set_log_group_retention_days(log_group_retention_days)

Arguments

log_group_retention_days

The number of days to retain the log events in the specified log group. AWS API Documentation


Method flush()

Usage

AppenderAWSCloudWatchLog$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
} # }