CodeSampleX

Sample

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

Verified sample for golang github.com/go-kit/log v0.1.0: level.AllowInfo. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:7ecf0b1bf1ba818a27ab5ac7cbde591fe23ee377cb52a66967d8eb776e2ebf3d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/go-kit/log/level.AllowInfo in pkg:golang/github.com/go-kit/log@v0.1.0
Packages
Symbols
  • github.com/go-kit/log/level.AllowInfo
Created
2026-09-04T02:51:47Z

Contract

  1. AllowInfo allows error, warn, and info level log events to pass through to the underlying logger
  2. AllowInfo squelches debug level log events by default without returning an error
  3. AllowInfo passes non-leveled log events through unmodified by default
  4. AllowInfo returns ErrNotAllowed when a disallowed debug log event is squelched
  5. AllowInfo with SquelchNoLevel squelches log events that lack a level
  6. AllowInfo works with contextual loggers created via log.With and log.NewLogfmtLogger

Files

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

Download the source artifact (tar.gz)

Source

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.AllowInfo 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.AllowInfo
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.
csx.json
{"case":{"caseId":"case:sha256:4d7b45c33b67b5cc41821eb92e086ae38af939da85095707dbcc9f6387a5dcbf","contract":["AllowInfo allows error, warn, and info level log events to pass through to the underlying logger","AllowInfo squelches debug level log events by default without returning an error","AllowInfo passes non-leveled log events through unmodified by default","AllowInfo returns ErrNotAllowed when a disallowed debug log event is squelched","AllowInfo with SquelchNoLevel squelches log events that lack a level","AllowInfo works with contextual loggers created via log.With and log.NewLogfmtLogger"],"goal":"verify github.com/go-kit/log/level.AllowInfo 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.AllowInfo"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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.AllowInfo"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

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.AllowInfo 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.AllowInfo"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

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

	"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. AllowInfo allows error, warn, and info level log events to pass through to the underlying logger
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo())

		if err := level.Error(filterLogger).Log("msg", "critical error"); err != nil {
			return fmt.Errorf("level.Error log failed: %w", err)
		}
		if err := level.Warn(filterLogger).Log("msg", "warning event"); err != nil {
			return fmt.Errorf("level.Warn log failed: %w", err)
		}
		if err := level.Info(filterLogger).Log("msg", "informational event"); err != nil {
			return fmt.Errorf("level.Info log failed: %w", err)
		}

		lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
		if len(lines) != 3 {
			return fmt.Errorf("expected 3 allowed lines, got %d", len(lines))
		}
		if lines[0] != `level=error msg="critical error"` {
			return fmt.Errorf("unexpected error line: %q", lines[0])
		}
		if lines[1] != `level=warn msg="warning event"` {
			return fmt.Errorf("unexpected warn line: %q", lines[1])
		}
		if lines[2] != `level=info msg="informational event"` {
			return fmt.Errorf("unexpected info line: %q", lines[2])
		}
	}

	// 2. AllowInfo squelches debug level log events by default without returning an error
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo())

		err := level.Debug(filterLogger).Log("msg", "debug detail", "code", 42)
		if err != nil {
			return fmt.Errorf("expected nil error on squelched debug log, got: %w", err)
		}
		if buf.Len() != 0 {
			return fmt.Errorf("expected empty buffer for squelched debug, got: %q", buf.String())
		}
	}

	// 3. AllowInfo passes non-leveled log events through unmodified by default
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo())

		if err := filterLogger.Log("msg", "unleveled event", "status", "ok"); err != nil {
			return fmt.Errorf("non-leveled log failed: %w", err)
		}
		out := strings.TrimSpace(buf.String())
		if out != `msg="unleveled event" status=ok` {
			return fmt.Errorf("unexpected unleveled output: %q", out)
		}
	}

	// 4. AllowInfo returns ErrNotAllowed when a disallowed debug log event is squelched
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		errDisallowed := errors.New("level not allowed")
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo(), level.ErrNotAllowed(errDisallowed))

		err := level.Debug(filterLogger).Log("msg", "debug event")
		if !errors.Is(err, errDisallowed) {
			return fmt.Errorf("expected ErrNotAllowed error, got: %v", err)
		}
		if buf.Len() != 0 {
			return fmt.Errorf("expected empty buffer on disallowed log, got: %q", buf.String())
		}

		// Info event should still pass and return nil
		if err := level.Info(filterLogger).Log("msg", "allowed info"); err != nil {
			return fmt.Errorf("info log should succeed with ErrNotAllowed option, got: %w", err)
		}
		out := strings.TrimSpace(buf.String())
		if out != `level=info msg="allowed info"` {
			return fmt.Errorf("unexpected info output: %q", out)
		}
	}

	// 5. AllowInfo with SquelchNoLevel squelches log events that lack a level
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		errNoLevel := errors.New("no level provided")
		filterLogger := level.NewFilter(
			baseLogger,
			level.AllowInfo(),
			level.SquelchNoLevel(true),
			level.ErrNoLevel(errNoLevel),
		)

		err := filterLogger.Log("msg", "missing level")
		if !errors.Is(err, errNoLevel) {
			return fmt.Errorf("expected ErrNoLevel error, got: %v", err)
		}
		if buf.Len() != 0 {
			return fmt.Errorf("expected empty buffer on squelched unleveled log, got: %q", buf.String())
		}

		// Leveled info event should pass
		if err := level.Info(filterLogger).Log("msg", "has level"); err != nil {
			return fmt.Errorf("leveled info log should pass, got: %w", err)
		}
		out := strings.TrimSpace(buf.String())
		if out != `level=info msg="has level"` {
			return fmt.Errorf("unexpected output: %q", out)
		}
	}

	// 6. AllowInfo works with contextual loggers created via log.With and log.NewLogfmtLogger
	{
		var buf bytes.Buffer
		baseLogger := log.NewLogfmtLogger(&buf)
		filterLogger := level.NewFilter(baseLogger, level.AllowInfo())
		ctxLogger := log.With(filterLogger, "service", "verifier")

		if err := level.Info(ctxLogger).Log("event", "started"); err != nil {
			return fmt.Errorf("context info log failed: %w", err)
		}
		if err := level.Debug(ctxLogger).Log("event", "ignored"); err != nil {
			return fmt.Errorf("context debug log failed: %w", err)
		}

		out := strings.TrimSpace(buf.String())
		if out != `level=info service=verifier event=started` {
			return fmt.Errorf("unexpected context logger output: %q", out)
		}
	}

	return nil
}

Origin Seeder

anonymous