샘플
github.com/go-logr/logr v1.4.1: funcr.NewJSON
검증된 샘플 — golang github.com/go-logr/logr v1.4.1: funcr.NewJSON. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: funcr.NewJSON creates a…
sha256:bd447a0114c25252ea3fbc6e8a70d9567b1cc3ac2ea01d2320019fc126cce151
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go linux 24 · ubuntu · glibc 2.39 x64 go go 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-27 |
케이스
HOW- 목표
- verify github.com/go-logr/logr/funcr.NewJSON in pkg:golang/github.com/go-logr/logr@v1.4.1
- 심벌
-
- github.com/go-logr/logr/funcr.NewJSON
- 환경
- go
- 생성일
- 2026-08-27T10:23:47Z
컨트랙트
- funcr.NewJSON creates a logr.Logger that serializes structured log messages and key-value arguments to JSON via a custom write sink.
- funcr.NewJSON formats error messages under the 'error' key and structured message strings under the 'msg' key.
- funcr.NewJSON preserves contextual logger names and key-value pairs added through WithName and WithValues.
- funcr.NewJSON filters log messages by verbosity level using Options.Verbosity and logger.V().
파일
- PROMPT.md
- csx.json
- funcr_test.go
- go.mod
- go.sum
- spec.json
소스
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 github.com/go-logr/logr/funcr.NewJSON in pkg:golang/github.com/go-logr/logr@v1.4.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-logr/logr@v1.4.1
Demonstrate these symbols/APIs:
- github.com/go-logr/logr/funcr.NewJSON
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:35039969bdbddfa17158b058843898115459a7427b9770e9e80c9696ebd97cd7","contract":["funcr.NewJSON creates a logr.Logger that serializes structured log messages and key-value arguments to JSON via a custom write sink.","funcr.NewJSON formats error messages under the 'error' key and structured message strings under the 'msg' key.","funcr.NewJSON preserves contextual logger names and key-value pairs added through WithName and WithValues.","funcr.NewJSON filters log messages by verbosity level using Options.Verbosity and logger.V()."],"goal":"verify github.com/go-logr/logr/funcr.NewJSON in pkg:golang/github.com/go-logr/logr@v1.4.1","kind":"HOW","packages":["pkg:golang/github.com/go-logr/logr@v1.4.1"],"schemaVersion":1,"symbols":["github.com/go-logr/logr/funcr.NewJSON"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/go-logr/logr@v1.4.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-logr/logr@v1.4.1","symbols":["github.com/go-logr/logr/funcr.NewJSON"],"verifierAdapter":"golang@1"}
package funcrjson_test
import (
"encoding/json"
"errors"
"testing"
"github.com/go-logr/logr"
"github.com/go-logr/logr/funcr"
)
func TestFuncrNewJSONBasic(t *testing.T) {
var logged []string
sink := func(obj string) {
logged = append(logged, obj)
}
var logger logr.Logger = funcr.NewJSON(sink, funcr.Options{})
logger.Info("service initialized", "port", 8080, "protocol", "tcp")
if len(logged) != 1 {
t.Fatalf("expected 1 log entry, got %d", len(logged))
}
var data map[string]interface{}
if err := json.Unmarshal([]byte(logged[0]), &data); err != nil {
t.Fatalf("failed to unmarshal JSON log: %v", err)
}
if data["msg"] != "service initialized" {
t.Errorf("expected msg 'service initialized', got %v", data["msg"])
}
if data["port"] != float64(8080) {
t.Errorf("expected port 8080, got %v", data["port"])
}
if data["protocol"] != "tcp" {
t.Errorf("expected protocol 'tcp', got %v", data["protocol"])
}
}
func TestFuncrNewJSONError(t *testing.T) {
var logged []string
sink := func(obj string) {
logged = append(logged, obj)
}
var logger logr.Logger = funcr.NewJSON(sink, funcr.Options{})
sampleErr := errors.New("connection reset by peer")
logger.Error(sampleErr, "failed to handle request", "retry", 3)
if len(logged) != 1 {
t.Fatalf("expected 1 log entry, got %d", len(logged))
}
var data map[string]interface{}
if err := json.Unmarshal([]byte(logged[0]), &data); err != nil {
t.Fatalf("failed to unmarshal JSON log: %v", err)
}
if data["msg"] != "failed to handle request" {
t.Errorf("expected msg 'failed to handle request', got %v", data["msg"])
}
if data["error"] != "connection reset by peer" {
t.Errorf("expected error 'connection reset by peer', got %v", data["error"])
}
if data["retry"] != float64(3) {
t.Errorf("expected retry 3, got %v", data["retry"])
}
}
func TestFuncrNewJSONWithValuesAndName(t *testing.T) {
var logged []string
sink := func(obj string) {
logged = append(logged, obj)
}
var baseLogger logr.Logger = funcr.NewJSON(sink, funcr.Options{})
namedLogger := baseLogger.WithName("authService").WithValues("tenantId", "tenant-123")
namedLogger.Info("user authentication successful", "userId", "user-456")
if len(logged) != 1 {
t.Fatalf("expected 1 log entry, got %d", len(logged))
}
var data map[string]interface{}
if err := json.Unmarshal([]byte(logged[0]), &data); err != nil {
t.Fatalf("failed to unmarshal JSON log: %v", err)
}
if data["logger"] != "authService" {
t.Errorf("expected logger 'authService', got %v", data["logger"])
}
if data["tenantId"] != "tenant-123" {
t.Errorf("expected tenantId 'tenant-123', got %v", data["tenantId"])
}
if data["userId"] != "user-456" {
t.Errorf("expected userId 'user-456', got %v", data["userId"])
}
if data["msg"] != "user authentication successful" {
t.Errorf("expected msg 'user authentication successful', got %v", data["msg"])
}
}
func TestFuncrNewJSONVerbosity(t *testing.T) {
var logged []string
sink := func(obj string) {
logged = append(logged, obj)
}
var logger logr.Logger = funcr.NewJSON(sink, funcr.Options{Verbosity: 1})
logger.V(0).Info("info level 0")
logger.V(1).Info("debug level 1")
logger.V(2).Info("trace level 2 (discarded)")
if len(logged) != 2 {
t.Fatalf("expected 2 logged entries, got %d", len(logged))
}
var entry1, entry2 map[string]interface{}
if err := json.Unmarshal([]byte(logged[0]), &entry1); err != nil {
t.Fatalf("failed to parse JSON: %v", err)
}
if err := json.Unmarshal([]byte(logged[1]), &entry2); err != nil {
t.Fatalf("failed to parse JSON: %v", err)
}
if entry1["msg"] != "info level 0" {
t.Errorf("entry 1 msg mismatch: %v", entry1["msg"])
}
if entry2["msg"] != "debug level 1" {
t.Errorf("entry 2 msg mismatch: %v", entry2["msg"])
}
if entry2["level"] != float64(1) {
t.Errorf("expected level 1, got %v", entry2["level"])
}
}
module example.com/funcrjson
go 1.22
require github.com/go-logr/logr v1.4.1
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
{
"schemaVersion": 1,
"goal": "verify github.com/go-logr/logr/funcr.NewJSON in pkg:golang/github.com/go-logr/logr@v1.4.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-logr/logr@v1.4.1"
],
"symbols": [
"github.com/go-logr/logr/funcr.NewJSON"
]
}
오리진 시더
익명