Implement structured logging package (log/slog)#15
Draft
Conversation
Co-authored-by: OkutaniDaichi0106 <132345842+OkutaniDaichi0106@users.noreply.github.com>
Co-authored-by: OkutaniDaichi0106 <132345842+OkutaniDaichi0106@users.noreply.github.com>
Co-authored-by: OkutaniDaichi0106 <132345842+OkutaniDaichi0106@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement structured logging package similar to Go's log/slog
Implement structured logging package (log/slog)
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a lightweight structured logging package inspired by Go's
log/slog, providing levels, handlers, formatters, and context propagation without external dependencies.Related Issue
Closes #(issue number not provided in context)
Changes
Core Types
Levelenum (Debug/Info/Warn/Error) with filtering supportLogRecordinterface capturing timestamp, level, message, key-value pairs, and optional errorsLoggerclass withdebug()/info()/warn()/error()methodswith(fields)for immutable context propagationwithGroup(name)for hierarchical key prefixesHandlers & Formatters
ConsoleHandler- routes to console.log/error based on levelFileHandler- async file appending with Deno APIsTextFormatter- human-readable:ISO LEVEL message key=val ...JSONFormatter- machine-readable single-line JSONAPI Surface
@okudai/golikejs/log/slog["k", v], and mixed formsExample
Testing
Checklist
Original prompt
This section details on the original issue you should resolve
<issue_title>[FEATURE] Implement structured logging package similar to Go's
log/slog</issue_title><issue_description>## Overview
Implement a lightweight, structured logging package for Go inspired by the standard library's log/slog. The package should provide levels, handlers, context/key-value support, formatters (text/JSON), and pluggable output targets.
Motivation & Benefits
Use Case
Proposed Solution (include Next Steps)
Alternatives Considered
Related issues
None
Checklist
<agent_instructions>Revised Copilot prompt (Deno-targeted, tests placed alongside sources as *_test.ts):
Implement a small TypeScript structured-logging package inspired by Go's log/slog. Context: use the repository ISSUE (.github/ISSUE_TEMPLATE/feature.yml) and refer to https://pkg.go.dev/log/slog for API guidance. Target runtime: Deno (no external deps). Place files under src/log/slog and export public API from src/log/slog/mod.ts.
Files to create:
Requirements (same as before, concise):
const root = new Logger(new ConsoleHandler({ level: Level.Info, formatter: new JSONFormatter() }));
const reqLogger = root.with({ requestId: "abc" });
reqLogger.info("started", ["user", 123], ["size", 42]);
reqLogger.error("failed", new Error("boom"));
Tests (minimal, Deno.test style in src/log/slog/slog_test.ts):
log/slog#14💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.