Home

CloudWatchLogs

Stable Latest Build Status CodeCov

CloudWatchLogs.jl provides easy access to CloudWatch Log Streams, and provides a Memento log handler.

Usage

Direct

CloudWatchLogs.jl uses AWSCore.jl for authentication and communication with Amazon Web Services. Many functions accept a config::AWSConfig parameter, which can be retrieved from AWSCore's aws_config function.

CloudWatch Log Streams can be created and deleted by name using create_stream and delete_stream. Those streams (or previously-existing streams) can be wrapped in a CloudWatchLogStream.

LogEvents are simply string messages and timestamps. By default, the timestamp is the current time. You can submit LogEvents to a CloudWatchLogStream using submit_logs or submit_log.

Here is an example:

using CloudWatchLogs
using AWSCore

config = aws_config()
stream = CloudWatchLogStream(
    config, "existing-log-group", create_stream("my-stream-$(uuid1())")
)
submit_log(stream, LogEvent("Hello, I'm a log"))
submit_logs(stream, [LogEvent("I'm log #$i") for i in 1:3])

With Memento

Single Process

CloudWatchLogs.jl also provides a log handler for Memento.jl.

To add a handler to the root logger:

push!(getlogger("root"), CloudWatchLogHandler(aws_config(), "my-log-group", "my-log-stream"))

Or, to add a handler to a package's logger:

# in the package's root module
const LOGGER = getlogger(@__MODULE__)

function __init__()
    Memento.register(LOGGER)
    push!(LOGGER, CloudWatchLogHandler(aws_config(), "my-log-group", "my-log-stream"))
end

Parallel Usage

Only one source can log to a CloudWatch Log Stream at a time, as each log submission must be submitted with the previous submission's sequence token. With Memento, this means you need a stream and handler for each process you will be logging to your logger from.

To add a handler with a unique stream to the root logger on each process:

@everywhere using Memento
@everywhere using UUIDs
@everywhere push!(getlogger("root"), CloudWatchLogHandler(aws_config(), "my-log-group", "my-log-stream-$(uuid1())"))

Or, to add a handler to a package's logger which will generate a new stream for each process it's loaded on:

# in the package's root module
const LOGGER = getlogger(@__MODULE__)

function __init__()
    Memento.register(LOGGER)
    push!(LOGGER, CloudWatchLogHandler(aws_config(), "my-log-group", "my-log-stream-$(uuid1())"))
end