Skip to content

Use slog (stdlib) as default logger, move logrus to subpackage#20

Merged
paganotoni merged 4 commits intomainfrom
use-slog-as-default
Mar 21, 2026
Merged

Use slog (stdlib) as default logger, move logrus to subpackage#20
paganotoni merged 4 commits intomainfrom
use-slog-as-default

Conversation

@paganotoni
Copy link
Member

Summary

This PR refactors the logger to use Go's standard library log/slog as the default implementation instead of logrus. The logrus implementation is moved to a subpackage for users who still need it.

Changes

  • Root package: Now uses log/slog (stdlib) with zero external dependencies
  • logrus subpackage: Contains the original logrus implementation
  • go.mod: Updated to require Go 1.25
  • Code modernization: Use any instead of interface{}
  • Documentation: Added package-level docs for both packages
  • Makefile: Removed legacy GO111MODULE checks

Benefits

  1. Smaller dependency tree: Users only depend on logrus if they explicitly import github.com/gobuffalo/logger/logrus
  2. Modern Go practices: Uses stdlib slog instead of third-party library
  3. Zero external dependencies for default usage
  4. Module graph pruning: Go will not download logrus for users who don't import the subpackage

Migration Guide

For existing users (no changes needed)

import "github.com/gobuffalo/logger"
log := logger.New(logger.InfoLevel)

For users who need logrus

import "github.com/gobuffalo/logger/logrus"
log := logrus.New(logrus.InfoLevel)

Breaking Changes

The default logger is now slog-based. While the Logger and FieldLogger interfaces remain the same, there may be subtle behavioral differences:

  • Log output format may differ slightly
  • Field handling uses slog attributes internally

Users relying on logrus-specific behavior should import the logrus subpackage.

This change makes the logger package use Go's standard library log/slog
as the default implementation instead of logrus. The logrus implementation
is moved to a subpackage (logrus/) for users who still need it.

Changes:
- Root package now uses log/slog (stdlib) - zero external dependencies
- logrus implementation moved to logrus/ subpackage
- Updated go.mod to require Go 1.25
- Modernized code: use 'any' instead of 'interface{}'
- Added package-level documentation
- Removed GO111MODULE checks from Makefile

Benefits:
- Users only depend on logrus if they explicitly import the subpackage
- Smaller dependency tree for most users
- Modern Go practices with slog

BREAKING CHANGE: The default logger is now slog-based. Users relying on
logrus-specific behavior should import github.com/gobuffalo/logger/logrus
@paganotoni paganotoni force-pushed the use-slog-as-default branch from 2420abc to 58b0e31 Compare March 20, 2026 23:51
- Update module path to github.com/gobuffalo/logger/v2
- Move slog implementation to unexported defaultFieldLogger in default.go
- Separate interfaces into logger.go (Logger, FieldLogger, Outable)
- Rename logrus.Logrus to unexported fieldLogger for consistency
- Update logrus dependency to v1.9.4
- Remove outable.go and slog.go (consolidated into default.go)

BREAKING CHANGE: Module path now includes /v2 suffix
@paganotoni paganotoni merged commit b55092c into main Mar 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant