CodeSampleX

샘플

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

검증된 샘플 — golang github.com/go-kit/log v0.1.0: level.AllowInfo. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: AllowInfo allows error, warn, and…

sha256:7ecf0b1bf1ba818a27ab5ac7cbde591fe23ee377cb52a66967d8eb776e2ebf3d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go go

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify github.com/go-kit/log/level.AllowInfo in pkg:golang/github.com/go-kit/log@v0.1.0
패키지
심벌
  • github.com/go-kit/log/level.AllowInfo
생성일
2026-09-04T02:51:47Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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
}

오리진 시더

익명