샘플
github.com/go-kit/log v0.2.1: NewLogfmtLogger, NewJSONLogger, With
검증된 샘플 — golang github.com/go-kit/log v0.2.1: NewLogfmtLogger, NewJSONLogger, With. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:4c44763d14139340391901ade894b536afe1028886da217c9675f781c7872e4a
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-23 |
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-07 |
케이스
HOW- 목표
- verify pkg:golang/github.com/go-kit/log@v0.2.1
- 심벌
-
- log.NewLogfmtLogger
- log.NewJSONLogger
- log.With
- log.Timestamp
- level.NewFilter
- log.NewSyncLogger
- 생성일
- 2026-08-23T17:34:20Z
컨트랙트
- log.NewLogfmtLogger formats structured key-value pairs into logfmt strings
- log.NewJSONLogger formats structured key-value pairs as valid JSON lines
- log.With preserves contextual key-value pairs across log invocations
- log.Timestamp dynamically evaluates timestamp Valuers on each log call
- level.NewFilter squelches debug messages and allows info and error messages
- log.NewSyncLogger provides thread-safe structured logging across concurrent goroutines
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/github.com/go-kit/log@v0.2.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-kit/log@v0.2.1
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:35bcd69f32978d1e89fe6fd252ad692332b98ffc06ae846dee85959326825eae","contract":["log.NewLogfmtLogger formats structured key-value pairs into logfmt strings","log.NewJSONLogger formats structured key-value pairs as valid JSON lines","log.With preserves contextual key-value pairs across log invocations","log.Timestamp dynamically evaluates timestamp Valuers on each log call","level.NewFilter squelches debug messages and allows info and error messages","log.NewSyncLogger provides thread-safe structured logging across concurrent goroutines"],"goal":"verify pkg:golang/github.com/go-kit/log@v0.2.1","kind":"HOW","packages":["pkg:golang/github.com/go-kit/log@v0.2.1"],"schemaVersion":1,"symbols":["log.NewLogfmtLogger","log.NewJSONLogger","log.With","log.Timestamp","level.NewFilter","log.NewSyncLogger"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/go-kit/log@v0.2.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-kit/log@v0.2.1","symbols":["log.NewLogfmtLogger","log.NewJSONLogger","log.With","log.Timestamp","level.NewFilter","log.NewSyncLogger"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/go-kit/log v0.2.1
require github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/go-kit/log@v0.2.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-kit/log@v0.2.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"sync"
"time"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
)
func main() {
if err := runTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract tests passed successfully.")
}
func runTests() error {
// 1. Test log.NewLogfmtLogger format encoding
var buf bytes.Buffer
logger := log.NewLogfmtLogger(&buf)
if err := logger.Log("msg", "hello world", "status", 200, "active", true); err != nil {
return fmt.Errorf("logfmt logger.Log failed: %w", err)
}
out := strings.TrimSpace(buf.String())
if out != `msg="hello world" status=200 active=true` {
return fmt.Errorf("unexpected logfmt output: %q", out)
}
// 2. Test log.NewJSONLogger format encoding
buf.Reset()
jsonLogger := log.NewJSONLogger(&buf)
if err := jsonLogger.Log("msg", "task started", "count", 42); err != nil {
return fmt.Errorf("JSON logger.Log failed: %w", err)
}
var data map[string]interface{}
if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
return fmt.Errorf("JSON unmarshal failed: %w (output: %q)", err, buf.String())
}
if data["msg"] != "task started" || data["count"] != float64(42) {
return fmt.Errorf("unexpected JSON output: %+v", data)
}
// 3. Test log.With context preservation
buf.Reset()
ctxLogger := log.With(logger, "service", "service-a", "env", "test")
if err := ctxLogger.Log("event", "process", "amount", 99.5); err != nil {
return fmt.Errorf("contextual logger.Log failed: %w", err)
}
out = strings.TrimSpace(buf.String())
if out != `service=service-a env=test event=process amount=99.5` {
return fmt.Errorf("unexpected contextual logfmt output: %q", out)
}
// 4. Test log.Valuer dynamic evaluation (e.g. Timestamp)
buf.Reset()
fixedTime := time.Date(2026, 8, 23, 12, 0, 0, 0, time.UTC)
timeValuer := log.Timestamp(func() time.Time {
return fixedTime
})
valLogger := log.With(logger, "ts", timeValuer)
if err := valLogger.Log("msg", "timestamped"); err != nil {
return fmt.Errorf("valuer logger.Log failed: %w", err)
}
out = strings.TrimSpace(buf.String())
if out != `ts=2026-08-23T12:00:00Z msg=timestamped` {
return fmt.Errorf("unexpected valuer output: %q", out)
}
// 5. Test level.NewFilter filtering behavior
buf.Reset()
filterLogger := level.NewFilter(logger, level.AllowInfo())
// Debug should be squelched (no output)
if err := level.Debug(filterLogger).Log("msg", "debug detail"); err != nil {
return fmt.Errorf("level.Debug log failed: %w", err)
}
if buf.Len() != 0 {
return fmt.Errorf("expected debug to be squelched, got: %q", buf.String())
}
// Info should be emitted
if err := level.Info(filterLogger).Log("msg", "info detail"); err != nil {
return fmt.Errorf("level.Info log failed: %w", err)
}
out = strings.TrimSpace(buf.String())
if out != `level=info msg="info detail"` {
return fmt.Errorf("unexpected level.Info output: %q", out)
}
// Error should be emitted
buf.Reset()
if err := level.Error(filterLogger).Log("msg", "error detail", "err", errors.New("operation failed")); err != nil {
return fmt.Errorf("level.Error log failed: %w", err)
}
out = strings.TrimSpace(buf.String())
if out != `level=error msg="error detail" err="operation failed"` {
return fmt.Errorf("unexpected level.Error output: %q", out)
}
// 6. Test log.NewSyncLogger concurrency safety
buf.Reset()
syncLogger := log.NewSyncLogger(logger)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(idx int) {
defer wg.Done()
_ = syncLogger.Log("worker", idx, "status", "ok")
}(i)
}
wg.Wait()
lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
if len(lines) != 10 {
return fmt.Errorf("expected 10 log lines from concurrent workers, got %d", len(lines))
}
return nil
}
오리진 시더
익명