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.
| Provider | Service | SDK-compat | Driver |
|---|---|---|---|
| AWS | CloudWatch Logs | ✓ Live | aws.CloudWatchLogs |
| Azure | Log Analytics | ✓ Live | azure.LogAnalytics |
| GCP | Cloud Logging | ✓ Live | gcp.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#
| Behavior | What happens |
|---|---|
| Timestamped, time-ordered events | A query filters a stream by StartTime and caps results with Limit, so you assert on exactly the window your code reads. |
| Named groups and streams | Events live under a group name and a stream name, matching how CloudWatch Logs namespaces a source. |
SDK-compat — Live#
Real CloudWatch Logs, Log Analytics, and Cloud Logging clients drive it end-to-end. See SDK-Compat for the full operation list.