LogGroup
Source:
src/AWS/Logs/LogGroup.ts
A CloudWatch Logs log group — the container for log streams and the unit that retention, encryption, metric filters, and subscriptions attach to.
Creating Log Groups
Section titled “Creating Log Groups”ECS Task Log Group
const logs = yield* LogGroup("TaskLogs", { retention: "7 days",});Encrypted Log Group with Deletion Protection
const key = yield* AWS.KMS.Key("LogsKey");const logs = yield* LogGroup("AuditLogs", { retention: "30 days", kmsKeyId: key.keyArn, deletionProtectionEnabled: true,});Writing Custom Log Events
Section titled “Writing Custom Log Events”Declare a LogStream and use the PutLogEvents binding inside a Lambda
function (or the batching LogEventSink for high-volume streams).
// initconst logGroup = yield* AWS.Logs.LogGroup("AuditLogs", { retention: "30 days",});const stream = yield* AWS.Logs.LogStream("AuditStream", { logGroupName: logGroup.logGroupName, logStreamName: "audit",});const putLogEvents = yield* AWS.Logs.PutLogEvents(logGroup);
// runtimeyield* putLogEvents({ logStreamName: "audit", logEvents: [{ timestamp, message: "user.login id=123" }],});Consuming Log Events
Section titled “Consuming Log Events”// Subscribe a Lambda handler to matching events (creates the// subscription filter + invoke permission automatically).yield* AWS.Logs.consumeLogEvents( logGroup, { filterPattern: "?ERROR ?Error" }, (events) => Stream.runForEach(events, (event) => Effect.log(`${event.logStream}: ${event.message}`), ),);Metrics
Section titled “Metrics”yield* AWS.Logs.MetricFilter("ErrorCount", { logGroupName: logGroup.logGroupName, filterPattern: '"ERROR"', metricTransformations: [{ metricName: "ErrorCount", metricNamespace: "MyApp", metricValue: "1", }],});