CodeSampleX

Sample

gopkg.in/natefinch/lumberjack.v2 v2.2.1: lumberjack.Logger.Write

Verified sample for golang gopkg.in/natefinch/lumberjack.v2 v2.2.1: lumberjack.Logger.Write. The contract ran on go 1.26 · linux alpine/x64 · docker and…

sha256:c7ce99b19fb143fe71c4c553b808103b52753ad5b5de1898225717601089db78

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
2
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 alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-26
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-07

Case

HOW
Goal
verify lumberjack.Logger.Write in pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1
Packages
Symbols
  • lumberjack.Logger.Write
Created
2026-08-26T01:25:37Z

Contract

  1. lumberjack.Logger implements io.WriteCloser
  2. lumberjack.Logger.Write writes log content to the active log file
  3. lumberjack.Logger.Write appends subsequent writes to the log file
  4. lumberjack.Logger.Close closes the active log file

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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 lumberjack.Logger.Write in pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1
Demonstrate these symbols/APIs:
  - lumberjack.Logger.Write
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:15f5026e2b21b203e7a007ad0a36d16d1eba2060242cebbc45082578b405cd22","contract":["lumberjack.Logger implements io.WriteCloser","lumberjack.Logger.Write writes log content to the active log file","lumberjack.Logger.Write appends subsequent writes to the log file","lumberjack.Logger.Close closes the active log file"],"goal":"verify lumberjack.Logger.Write in pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1","kind":"HOW","packages":["pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1"],"schemaVersion":1,"symbols":["lumberjack.Logger.Write"]},"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/gopkg.in/natefinch/lumberjack.v2@v2.2.1"],"schemaVersion":1,"subject":"pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1","symbols":["lumberjack.Logger.Write"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require gopkg.in/natefinch/lumberjack.v2 v2.2.1
go.sum
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
sample.go
package sample

import (
	"gopkg.in/natefinch/lumberjack.v2"
)

// NewLogger creates a new configured lumberjack.Logger.
func NewLogger(filename string, maxSizeMB int, maxBackups int) *lumberjack.Logger {
	return &lumberjack.Logger{
		Filename:   filename,
		MaxSize:    maxSizeMB,
		MaxBackups: maxBackups,
		LocalTime:  true,
		Compress:   false,
	}
}

// LogMessage writes bytes to the logger using Write.
func LogMessage(l *lumberjack.Logger, msg []byte) (int, error) {
	return l.Write(msg)
}

// CloseLogger closes the active log file.
func CloseLogger(l *lumberjack.Logger) error {
	return l.Close()
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify lumberjack.Logger.Write in pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/gopkg.in/natefinch/lumberjack.v2@v2.2.1"
  ],
  "symbols": [
    "lumberjack.Logger.Write"
  ],
  "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"
	"fmt"
	"io"
	"os"
	"path/filepath"

	"gopkg.in/natefinch/lumberjack.v2"
	"sample"
)

func main() {
	tmpDir, err := os.MkdirTemp("", "lumberjack-test-*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create temp dir: %v\n", err)
		os.Exit(1)
	}
	defer os.RemoveAll(tmpDir)

	logPath := filepath.Join(tmpDir, "app.log")

	// Assertion 1: lumberjack.Logger implements io.WriteCloser
	logger := sample.NewLogger(logPath, 1, 3)
	var _ io.WriteCloser = logger
	var _ *lumberjack.Logger = logger

	// Assertion 2: lumberjack.Logger.Write writes log content to the active log file
	msg1 := []byte("first log line\n")
	n, err := sample.LogMessage(logger, msg1)
	if err != nil {
		fmt.Fprintf(os.Stderr, "LogMessage failed: %v\n", err)
		os.Exit(1)
	}
	if n != len(msg1) {
		fmt.Fprintf(os.Stderr, "expected %d bytes written, got %d\n", len(msg1), n)
		os.Exit(1)
	}

	content, err := os.ReadFile(logPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read log file: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(content, msg1) {
		fmt.Fprintf(os.Stderr, "expected content %q, got %q\n", string(msg1), string(content))
		os.Exit(1)
	}

	// Assertion 3: lumberjack.Logger.Write appends consecutive log writes
	msg2 := []byte("second log line\n")
	n2, err := sample.LogMessage(logger, msg2)
	if err != nil {
		fmt.Fprintf(os.Stderr, "LogMessage second write failed: %v\n", err)
		os.Exit(1)
	}
	if n2 != len(msg2) {
		fmt.Fprintf(os.Stderr, "expected %d bytes written, got %d\n", len(msg2), n2)
		os.Exit(1)
	}

	appendedContent, err := os.ReadFile(logPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read log file after second write: %v\n", err)
		os.Exit(1)
	}
	expectedAppended := append(msg1, msg2...)
	if !bytes.Equal(appendedContent, expectedAppended) {
		fmt.Fprintf(os.Stderr, "expected combined content %q, got %q\n", string(expectedAppended), string(appendedContent))
		os.Exit(1)
	}

	// Assertion 4: lumberjack.Logger.Close closes the active log file
	if err := sample.CloseLogger(logger); err != nil {
		fmt.Fprintf(os.Stderr, "CloseLogger failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("All lumberjack.Logger.Write contract assertions passed.")
}

Origin Seeder

anonymous