CodeSampleX

Exemplo

github.com/go-kit/log v0.1.0: level.Debug

Amostra verificada para golang github.com/go-kit/log v0.1.0: level.Debug. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:5521a6a980a0abdfb561a101c01ac9353520ab4f3399c60692b0cb9c1d225cd0

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 linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-04

Caso

HOW
Objetivo
verify github.com/go-kit/log/level.Debug in pkg:golang/github.com/go-kit/log@v0.1.0
Pacotes
Símbolos
  • github.com/go-kit/log/level.Debug
Criado
2026-09-04T03:51:38Z

Contrato

  1. level.Debug decorates a logger to prepend level key and debug value to log records
  2. level.Debug produces formatted debug output in JSON logger
  3. level.NewFilter squelches level.Debug calls when configured with AllowInfo
  4. level.NewFilter permits level.Debug calls when configured with AllowDebug
  5. level.NewFilter with ErrNotAllowed returns configured error when level.Debug is squelched

Arquivos

  • PROMPT.md
  • csx.json
  • debug.go
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

PROMPT.md
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-kit/log/level.Debug in pkg:golang/github.com/go-kit/log@v0.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/go-kit/log@v0.1.0
Demonstrate these symbols/APIs:
  - github.com/go-kit/log/level.Debug

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.
csx.json
{"case":{"caseId":"case:sha256:c7e3765b188bb92661e2a380a86f641426e4ac25ecb4828effc07ef945e55210","contract":["level.Debug decorates a logger to prepend level key and debug value to log records","level.Debug produces formatted debug output in JSON logger","level.NewFilter squelches level.Debug calls when configured with AllowInfo","level.NewFilter permits level.Debug calls when configured with AllowDebug","level.NewFilter with ErrNotAllowed returns configured error when level.Debug is squelched"],"goal":"verify github.com/go-kit/log/level.Debug in pkg:golang/github.com/go-kit/log@v0.1.0","kind":"HOW","packages":["pkg:golang/github.com/go-kit/log@v0.1.0"],"schemaVersion":1,"symbols":["github.com/go-kit/log/level.Debug"]},"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.1.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-kit/log@v0.1.0","symbols":["github.com/go-kit/log/level.Debug"],"verifierAdapter":"golang@1"}
debug.go
package sample

import (
	"github.com/go-kit/log"
	"github.com/go-kit/log/level"
)

// LogDebug logs a debug-level message with key-value pairs using level.Debug.
func LogDebug(logger log.Logger, keyvals ...interface{}) error {
	return level.Debug(logger).Log(keyvals...)
}

// NewDebugFilter returns a filtered logger that permits debug level and above.
func NewDebugFilter(logger log.Logger) log.Logger {
	return level.NewFilter(logger, level.AllowDebug())
}

// NewInfoFilter returns a filtered logger that squelches debug level events.
func NewInfoFilter(logger log.Logger) log.Logger {
	return level.NewFilter(logger, level.AllowInfo())
}
go.mod
module example.com/gokit-level-debug

go 1.22.0

require github.com/go-kit/log v0.1.0

require github.com/go-logfmt/logfmt v0.5.0 // indirect
go.sum
github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/go-kit/log/level.Debug in pkg:golang/github.com/go-kit/log@v0.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/go-kit/log@v0.1.0"
  ],
  "symbols": [
    "github.com/go-kit/log/level.Debug"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"errors"
	"fmt"
	"os"
	"strings"

	"github.com/go-kit/log"
	"github.com/go-kit/log/level"
	sample "example.com/gokit-level-debug"
)

func main() {
	// Assertion 1: level.Debug decorates a logger to prepend level key and debug value to log records
	{
		var buf bytes.Buffer
		logger := log.NewLogfmtLogger(&buf)
		debugLogger := level.Debug(logger)
		err := debugLogger.Log("msg", "processing item", "id", 101)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 1 failed: %v\n", err)
			os.Exit(1)
		}
		expected := "level=debug msg=\"processing item\" id=101\n"
		if buf.String() != expected {
			fmt.Fprintf(os.Stderr, "Contract 1 failed: expected %q, got %q\n", expected, buf.String())
			os.Exit(1)
		}
	}

	// Assertion 2: level.Debug produces formatted debug output in JSON logger
	{
		var buf bytes.Buffer
		jsonLogger := log.NewJSONLogger(&buf)
		err := level.Debug(jsonLogger).Log("event", "cache_lookup", "hit", true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: %v\n", err)
			os.Exit(1)
		}
		out := strings.TrimSpace(buf.String())
		expected := `{"event":"cache_lookup","hit":true,"level":"debug"}`
		if out != expected {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: expected %q, got %q\n", expected, out)
			os.Exit(1)
		}
	}

	// Assertion 3: level.NewFilter squelches level.Debug calls when configured with AllowInfo
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo())

		err := level.Debug(filterLogger).Log("msg", "diagnostic details")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: expected nil error on squelch, got %v\n", err)
			os.Exit(1)
		}
		if buf.Len() != 0 {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: expected empty buffer for squelched debug log, got %q\n", buf.String())
			os.Exit(1)
		}

		err = level.Info(filterLogger).Log("msg", "system operational")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: %v\n", err)
			os.Exit(1)
		}
		expectedInfo := "level=info msg=\"system operational\"\n"
		if buf.String() != expectedInfo {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: expected %q, got %q\n", expectedInfo, buf.String())
			os.Exit(1)
		}
	}

	// Assertion 4: level.NewFilter permits level.Debug calls when configured with AllowDebug
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowDebug())

		err := level.Debug(filterLogger).Log("msg", "verbose tracing", "step", 2)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: %v\n", err)
			os.Exit(1)
		}
		expected := "level=debug msg=\"verbose tracing\" step=2\n"
		if buf.String() != expected {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: expected %q, got %q\n", expected, buf.String())
			os.Exit(1)
		}
	}

	// Assertion 5: level.NewFilter with ErrNotAllowed returns configured error when level.Debug is squelched
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		errNotAllowed := errors.New("log level not permitted")
		filterLogger := level.NewFilter(baseLogger, level.AllowWarn(), level.ErrNotAllowed(errNotAllowed))

		err := level.Debug(filterLogger).Log("msg", "should return error")
		if !errors.Is(err, errNotAllowed) {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: expected errNotAllowed, got %v\n", err)
			os.Exit(1)
		}
		if buf.Len() != 0 {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: expected empty buffer, got %q\n", buf.String())
			os.Exit(1)
		}
	}

	// Assertion 6: sample package helpers verify level.Debug integration
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)

		debugLogger := sample.NewDebugFilter(baseLogger)
		if err := sample.LogDebug(debugLogger, "component", "auth", "event", "token_verified"); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: %v\n", err)
			os.Exit(1)
		}
		expected := "level=debug component=auth event=token_verified\n"
		if buf.String() != expected {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: expected %q, got %q\n", expected, buf.String())
			os.Exit(1)
		}

		buf.Reset()
		infoLogger := sample.NewInfoFilter(baseLogger)
		if err := sample.LogDebug(infoLogger, "component", "auth", "event", "ignored_trace"); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: %v\n", err)
			os.Exit(1)
		}
		if buf.Len() != 0 {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: expected empty buffer for filtered debug log, got %q\n", buf.String())
			os.Exit(1)
		}
	}

	fmt.Println("All level.Debug contract assertions passed.")
}

Seeder de origem

anônimo