Skip to content

feat(logger): add ISO 8601 timestamps to log output (closes #97)#125

Open
komoreka wants to merge 1 commit into
stoneforge-ai:masterfrom
komoreka:feat/logger-timestamps
Open

feat(logger): add ISO 8601 timestamps to log output (closes #97)#125
komoreka wants to merge 1 commit into
stoneforge-ai:masterfrom
komoreka:feat/logger-timestamps

Conversation

@komoreka
Copy link
Copy Markdown
Contributor

Summary

Adds an ISO 8601 timestamp prefix to every log line emitted by createLogger in packages/smithy/src/utils/logger.ts.

Before:

[dispatch-daemon] Spawned worker el-4w8y for task el-2xyz
[cost-service] No pricing found for model "..."

After:

2026-05-05T08:21:44.123Z [dispatch-daemon] Spawned worker el-4w8y for task el-2xyz
2026-05-05T08:21:44.125Z [cost-service] No pricing found for model "..."

Closes #97.

Changes

  • packages/smithy/src/utils/logger.ts: exports a new timestampsEnabled() helper that reads LOG_TIMESTAMPS fresh on each call (same pattern as the existing getLogLevel()). The createLogger factory's inner emit helper uses it to prepend new Date().toISOString() before the [service-name] prefix when enabled.
  • packages/smithy/src/utils/logger.bun.test.ts: 14 new tests covering timestamp format, opt-out behavior, extra args pass-through, and all four log levels.
  • packages/smithy/src/services/steward-scheduler.test.ts: updated three existing spy assertions to expect the new leading timestamp argument.
  • .changeset/logger-timestamps.md: patch bump for @stoneforge/smithy.

Opt-out

Set LOG_TIMESTAMPS=0 to disable the prefix:

LOG_TIMESTAMPS=0 sf serve smithy

This matches the existing LOG_LEVEL env-var pattern and is useful when piping to systemd, journald, or any other log aggregator that adds its own timestamps.

Test plan

  • bun test packages/smithy/src/utils/logger.bun.test.ts passes (14/14)
  • Full smithy test suite: 1582 pass, 0 fail
  • NODE_ENV=development npx turbo run typecheck --filter=@stoneforge/smithy clean

Closes stoneforge-ai#97.

- Every log line now starts with the current ISO 8601 timestamp so
  long-running sf serve smithy output can be scanned or correlated
  across services without external time markers.
- Opt-out: set LOG_TIMESTAMPS=0 (e.g. when piping to systemd/journald).
- Adds 14 unit tests covering timestamp format, opt-out, and all four
  log levels.
- Updates three existing steward-scheduler spy assertions to account
  for the new leading timestamp argument.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logger: add timestamps to log output for easier scanning

1 participant