migrate-zap-to-slog

Migrate Go projects from go.uber.org/zap to log/slog.

Updated Aug 9, 2022
One-click install
npx skills add https://github.com/BizShuk/gosdk --skill migrate-zap-to-slog
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrate-zap-to-slog
Source: https://github.com/BizShuk/gosdk/tree/main/skills/migrate-zap-to-slog
Command: npx skills add https://github.com/BizShuk/gosdk --skill migrate-zap-to-slog

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the overhead of maintaining the third-party go.uber.org/zap logging dependency in Go projects, allowing teams to adopt the built-in log/slog package (introduced in Go 1.21) to reduce external dependencies and align with standard library tooling.

Core Features & Use Cases

  • Complete API Mapping: Includes a full reference table to translate all common zap logging calls (including Sugar-style formatted calls and Fatal levels, which have no direct slog equivalent) to correct log/slog syntax.
  • Viper-Compatible Log Initializer: Provides a ready-to-use log setup implementation that supports LOG_LEVEL and LOG_FORMAT configuration via viper, matching the configuration patterns used in the gosdk repository.
  • Use Case: Perfect for Go teams modernizing their logging stack, eliminating the zap dependency, or ensuring new code uses only standard library logging tooling.

Quick Start

Use the migrate-zap-to-slog skill to replace all go.uber.org/zap imports and call sites in your Go project with standard log/slog equivalents.

Frequently Asked Questions about migrate-zap-to-slog

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate my Go project from zap to slog?

To migrate from zap to slog, you replace go.uber.org/zap imports and call sites with standard log/slog equivalents. This process utilizes complete API mapping tables to translate common zap logging calls to correct log/slog syntax.

What is the equivalent of zap.L() and zap.S() in Go's log/slog?

The equivalent of zap.L() and zap.S() in Go's log/slog is handled through complete API mapping tables. These tables translate specific zap call sites into the correct standard log/slog syntax for your codebase.

How do I handle zap Fatal level logging when switching to slog?

Handling zap Fatal level logging when switching to slog requires specific translation because Fatal levels have no direct slog equivalent. The migration provides an API mapping table to correctly handle these Sugar-style formatted calls.

Can I configure slog log levels using viper like my previous zap setup?

Yes, you can configure slog log levels using viper. The migration provides a ready-to-use log initializer implementation that supports LOG_LEVEL and LOG_FORMAT configuration via viper, matching existing setup patterns.

Why should I replace the go.uber.org/zap dependency with standard log/slog?

Replacing the go.uber.org/zap dependency with standard log/slog eliminates the overhead of maintaining third-party logging libraries. It allows Go teams to reduce external dependencies and align with standard library tooling introduced in Go 1.21.