Exemplo
github.com/go-logr/stdr v1.2.2: Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging
Amostra verificada para golang github.com/go-logr/stdr v1.2.2: Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging. O…
sha256:a488bf78f1e4fe8991fefd0681ff8709926e12b900a1af8fcfc83cfd57e0ebd8
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
windows 11 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-19 |
Caso
HOW- Objetivo
- Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging
- Pacotes
- Símbolos
-
- stdr.New
- Criado
- 2026-08-18T18:13:03Z
Contrato
- stdr.New creates a logr.Logger wrapping a stdlib log.Logger
- logger.Info writes formatted message and key-value pairs to log output
- logger.Error writes error message and error details to log output
- logger.WithName and WithValues adds context to log records
- stdr.SetVerbosity controls V-level message output
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
Código-fonte
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: Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-logr/stdr@v1.2.2
Demonstrate these symbols/APIs:
- stdr.New
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@11.8.0
- runtime: node@24.13.1
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:e6673b24b11a2bc36b89b86cacc7bd54bdf429b46f14d765fe6e3bda6248c7fa","contract":["stdr.New creates a logr.Logger wrapping a stdlib log.Logger","logger.Info writes formatted message and key-value pairs to log output","logger.Error writes error message and error details to log output","logger.WithName and WithValues adds context to log records","stdr.SetVerbosity controls V-level message output"],"goal":"Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging","kind":"HOW","packages":["pkg:golang/github.com/go-logr/stdr@v1.2.2"],"schemaVersion":1,"symbols":["stdr.New"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","os":"windows","osVersionBucket":"11","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/go-logr/stdr@v1.2.2"],"schemaVersion":1,"symbols":["stdr.New"],"verifierAdapter":"golang@1"}
module sample
go 1.21
require (
github.com/go-logr/logr v1.2.2
github.com/go-logr/stdr v1.2.2
)
github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
{
"schemaVersion": 1,
"goal": "Create a logr.Logger using stdr.New with stdlib log.Logger and verify Info/Error logging",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-logr/stdr@v1.2.2"
],
"symbols": [
"stdr.New"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"log"
"os"
"strings"
"github.com/go-logr/stdr"
)
func main() {
var buf bytes.Buffer
stdLog := log.New(&buf, "", 0)
// 1. stdr.New creates a logr.Logger wrapping a stdlib log.Logger
logger := stdr.New(stdLog)
// 2. logger.Info writes formatted message and key-value pairs to log output
buf.Reset()
logger.Info("server starting", "port", 8080, "env", "prod")
infoOut := buf.String()
if !strings.Contains(infoOut, `"level"=0`) || !strings.Contains(infoOut, `"msg"="server starting"`) || !strings.Contains(infoOut, `"port"=8080`) || !strings.Contains(infoOut, `"env"="prod"`) {
fmt.Fprintf(os.Stderr, "unexpected Info log output: %q\n", infoOut)
os.Exit(1)
}
// 3. logger.Error writes error message and error details to log output
buf.Reset()
testErr := errors.New("connection refused")
logger.Error(testErr, "failed to connect", "host", "example.com")
errOut := buf.String()
if !strings.Contains(errOut, `"msg"="failed to connect"`) || !strings.Contains(errOut, `"error"="connection refused"`) || !strings.Contains(errOut, `"host"="example.com"`) {
fmt.Fprintf(os.Stderr, "unexpected Error log output: %q\n", errOut)
os.Exit(1)
}
// 4. logger.WithName and WithValues adds context to log records
buf.Reset()
namedLogger := logger.WithName("worker").WithValues("workerId", 42)
namedLogger.Info("job finished", "status", "ok")
namedOut := buf.String()
if !strings.Contains(namedOut, "worker:") || !strings.Contains(namedOut, `"workerId"=42`) || !strings.Contains(namedOut, `"status"="ok"`) {
fmt.Fprintf(os.Stderr, "unexpected named logger output: %q\n", namedOut)
os.Exit(1)
}
// 5. stdr.SetVerbosity controls V-level message output
buf.Reset()
logger.V(1).Info("hidden debug message")
if buf.Len() != 0 {
fmt.Fprintf(os.Stderr, "expected V(1) log to be discarded at default verbosity, got: %q\n", buf.String())
os.Exit(1)
}
stdr.SetVerbosity(1)
buf.Reset()
logger.V(1).Info("visible debug message", "step", 1)
vOut := buf.String()
if !strings.Contains(vOut, `"level"=1`) || !strings.Contains(vOut, `"msg"="visible debug message"`) || !strings.Contains(vOut, `"step"=1`) {
fmt.Fprintf(os.Stderr, "unexpected V(1) log output after SetVerbosity: %q\n", vOut)
os.Exit(1)
}
fmt.Println("github.com/go-logr/stdr contract verified successfully")
}
Seeder de origem
anônimo