Skip to content
cloudemu
Services

Logging

Log groups, streams, and event queries, modelled on CloudWatch Logs, Log Analytics, and Cloud Logging

aws CloudWatch Logsazr Log Analyticsgcp Cloud Logging

Emulates a managed log store — the CloudWatch Logs pipeline your app writes events into and you later query. You create a log group, open a stream within it, put events onto the stream, then read them back by time range.

Reach for it in tests when your code emits log events, sets retention, or queries a window of history — so you can exercise those paths without a live logging backend. Under the hood a group is a named container, a stream is an ordered sequence of timestamped events inside it, and a query filters that sequence by time.

ProviderServiceDriver
AWSCloudWatch Logsaws.CloudWatchLogs
AzureLog Analyticsazure.LogAnalytics
GCPCloud Logginggcp.CloudLogging

Create groups and streams, then write events#

A log group is the top-level container (with a retention window), a stream is a single source of events within it, and PutLogEvents appends timestamped messages — the same three steps you'd take with CloudWatch Logs:

import logdriver "github.com/stackshy/cloudemu/v2/services/logging/driver"

// Create a log group
aws.CloudWatchLogs.CreateLogGroup(ctx, logdriver.LogGroupConfig{
    Name:           "/app/web",
    RetentionDays:  30,
})

// Create a log stream
aws.CloudWatchLogs.CreateLogStream(ctx, "/app/web", "instance-001")

// Put log events
aws.CloudWatchLogs.PutLogEvents(ctx, "/app/web", "instance-001", []logdriver.LogEvent{
    {Timestamp: time.Now(), Message: "Server started on port 8080"},
    {Timestamp: time.Now(), Message: "Handling request GET /api/users"},
})

Query events#

GetLogEvents reads back a stream over a time window with a limit, the way you'd scan recent history in the console or an alerting job:

events, _ := aws.CloudWatchLogs.GetLogEvents(ctx, "/app/web", "instance-001",
    logdriver.GetLogEventsInput{
        StartTime: time.Now().Add(-1 * time.Hour),
        Limit:     100,
    })

To test retention or time-windowed queries without waiting, drive time with the fake clock: advance the clock and query a window that spans the jump.

Behavior & fidelity#

  • Events are timestamped and time-ordered. A query filters a stream by StartTime and caps results with Limit, so you can assert on exactly the window your code reads.
  • Groups and streams are addressed by name. Events live under a group name and a stream name, matching how CloudWatch Logs namespaces a source.
  • SDK-compat status — Portable Go API only. Real aws-sdk-go-v2/service/cloudwatchlogs, Log Analytics REST, and Cloud Logging REST clients can't talk to cloudemu yet — logging SDK-compat handlers will ship in lockstep across all three providers in a future phase. Groups, streams, and event queries are available today through the Portable Go API shown above.

On this page

On this page