CodeSampleX

Sample

github.com/rs/zerolog v1.15.0: GlobalLevel

Verified sample for golang github.com/rs/zerolog v1.15.0: GlobalLevel. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:a28951aa3f614096ffcd95d934de8b5e31e62e4101bbfa249384dce2e024e8f7

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

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-15

Case

HOW
Goal
verify github.com/rs/zerolog.GlobalLevel in pkg:golang/github.com/rs/zerolog@v1.15.0
Packages
Symbols
  • github.com/rs/zerolog.GlobalLevel
Created
2026-09-15T03:11:31Z

Contract

  1. zerolog.GlobalLevel returns the active global logging Level
  2. zerolog.SetGlobalLevel updates the level returned by zerolog.GlobalLevel
  3. zerolog.GlobalLevel filters log events below the configured threshold
  4. zerolog.GlobalLevel set to zerolog.Disabled prevents any log output from being emitted
  5. zerolog.GlobalLevel value corresponds to the defined zerolog.Level uint8 constants

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • 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/rs/zerolog.GlobalLevel in pkg:golang/github.com/rs/zerolog@v1.15.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/rs/zerolog@v1.15.0
Demonstrate these symbols/APIs:
  - github.com/rs/zerolog.GlobalLevel

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:8f7a7f4ab0f6aeb68dbd46186d2db9c8d8255ed32a7bcc979d568fd03669b215","contract":["zerolog.GlobalLevel returns the active global logging Level","zerolog.SetGlobalLevel updates the level returned by zerolog.GlobalLevel","zerolog.GlobalLevel filters log events below the configured threshold","zerolog.GlobalLevel set to zerolog.Disabled prevents any log output from being emitted","zerolog.GlobalLevel value corresponds to the defined zerolog.Level uint8 constants"],"goal":"verify github.com/rs/zerolog.GlobalLevel in pkg:golang/github.com/rs/zerolog@v1.15.0","kind":"HOW","packages":["pkg:golang/github.com/rs/zerolog@v1.15.0"],"schemaVersion":1,"symbols":["github.com/rs/zerolog.GlobalLevel"]},"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/rs/zerolog@v1.15.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/rs/zerolog@v1.15.0","symbols":["github.com/rs/zerolog.GlobalLevel"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/rs/zerolog v1.15.0
go.sum
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/rs/zerolog"
)

func main() {
	// 1. Inspect current global level
	initial := zerolog.GlobalLevel()
	fmt.Printf("Initial global log level: %s\n", initial)

	// 2. Set global level to InfoLevel
	zerolog.SetGlobalLevel(zerolog.InfoLevel)
	current := zerolog.GlobalLevel()
	fmt.Printf("Updated global log level: %s\n", current)

	logger := zerolog.New(os.Stdout).With().Timestamp().Logger()

	// 3. Debug event is suppressed because GlobalLevel is InfoLevel
	logger.Debug().Msg("This debug message will not be logged")

	// 4. Info and Warn events are emitted
	logger.Info().Str("status", "ok").Msg("Service initialized")
	logger.Warn().Int("retries", 1).Msg("Temporary network glitch")

	// 5. Disable all log output globally
	zerolog.SetGlobalLevel(zerolog.Disabled)
	fmt.Printf("Disabled global log level: %s\n", zerolog.GlobalLevel())
	logger.Error().Msg("This error message will not be logged")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/rs/zerolog.GlobalLevel in pkg:golang/github.com/rs/zerolog@v1.15.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/rs/zerolog@v1.15.0"
  ],
  "symbols": [
    "github.com/rs/zerolog.GlobalLevel"
  ]
}
test/contract.go
package main

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

	"github.com/rs/zerolog"
)

func main() {
	origLevel := zerolog.GlobalLevel()
	defer zerolog.SetGlobalLevel(origLevel)

	// 1. zerolog.GlobalLevel returns the active global logging Level
	initialLevel := zerolog.GlobalLevel()
	if initialLevel != zerolog.DebugLevel {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected default level DebugLevel, got %v\n", initialLevel)
		os.Exit(1)
	}

	// 2. zerolog.SetGlobalLevel updates the level returned by zerolog.GlobalLevel
	testLevels := []zerolog.Level{
		zerolog.InfoLevel,
		zerolog.WarnLevel,
		zerolog.ErrorLevel,
		zerolog.DebugLevel,
	}
	for _, lvl := range testLevels {
		zerolog.SetGlobalLevel(lvl)
		if got := zerolog.GlobalLevel(); got != lvl {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %v, got %v\n", lvl, got)
			os.Exit(1)
		}
	}

	// 3. zerolog.GlobalLevel filters log events below the configured threshold
	zerolog.SetGlobalLevel(zerolog.InfoLevel)
	var buf bytes.Buffer
	logger := zerolog.New(&buf)

	logger.Debug().Msg("debug-filtered")
	if buf.Len() != 0 {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: debug message was not filtered: %s\n", buf.String())
		os.Exit(1)
	}

	logger.Info().Msg("info-included")
	if !strings.Contains(buf.String(), "info-included") {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: info message missing: %s\n", buf.String())
		os.Exit(1)
	}
	buf.Reset()

	logger.Warn().Msg("warn-included")
	if !strings.Contains(buf.String(), "warn-included") {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: warn message missing: %s\n", buf.String())
		os.Exit(1)
	}
	buf.Reset()

	// 4. zerolog.GlobalLevel set to zerolog.Disabled prevents any log output from being emitted
	zerolog.SetGlobalLevel(zerolog.Disabled)
	if got := zerolog.GlobalLevel(); got != zerolog.Disabled {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: expected Disabled, got %v\n", got)
		os.Exit(1)
	}

	logger.Error().Msg("error-suppressed")
	logger.Warn().Msg("warn-suppressed")
	if buf.Len() != 0 {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: output emitted while disabled: %s\n", buf.String())
		os.Exit(1)
	}

	// 5. zerolog.GlobalLevel value corresponds to the defined zerolog.Level uint8 constants
	zerolog.SetGlobalLevel(zerolog.WarnLevel)
	current := zerolog.GlobalLevel()
	if current.String() != "warn" {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: expected level string 'warn', got %q\n", current.String())
		os.Exit(1)
	}
	if uint8(current) != 2 {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: expected uint8 value 2 for WarnLevel, got %d\n", uint8(current))
		os.Exit(1)
	}

	fmt.Println("All zerolog.GlobalLevel contract assertions passed.")
}

Origin Seeder

anonymous