1
0
mirror of https://github.com/regclient/regclient.git synced 2025-04-18 22:44:00 +03:00

Feat: Move logrus calls into files excluded by wasm

This permits builds of wasm binaries.

Signed-off-by: Brandon Mitchell <git@bmitch.net>
This commit is contained in:
Brandon Mitchell 2024-11-12 10:18:24 -05:00
parent 3a4d032d53
commit 289533b02c
No known key found for this signature in database
GPG Key ID: 6E0FF28C767A8BEE
9 changed files with 68 additions and 35 deletions

View File

@ -17,7 +17,6 @@ import (
"github.com/opencontainers/go-digest"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/regclient/regclient"
@ -120,7 +119,7 @@ sync step is finished.`,
}
rootTopCmd.PersistentFlags().StringVarP(&rootOpts.confFile, "config", "c", "", "Config file")
rootTopCmd.PersistentFlags().StringVarP(&rootOpts.verbosity, "verbosity", "v", logrus.InfoLevel.String(), "Log level (debug, info, warn, error, fatal, panic)")
rootTopCmd.PersistentFlags().StringVarP(&rootOpts.verbosity, "verbosity", "v", slog.LevelInfo.String(), "Log level (debug, info, warn, error, fatal, panic)")
rootTopCmd.PersistentFlags().StringArrayVar(&rootOpts.logopts, "logopt", []string{}, "Log options")
versionCmd.Flags().StringVar(&rootOpts.format, "format", "{{printPretty .}}", "Format output with go template syntax")
onceCmd.Flags().BoolVar(&rootOpts.missing, "missing", false, "Only copy tags that are missing on target")

View File

@ -1,3 +1,6 @@
//go:build !wasm
// +build !wasm
// Package sloghandle provides a transition handler for migrating from logrus to slog.
package sloghandle

View File

@ -1,3 +1,6 @@
//go:build !wasm
// +build !wasm
package sloghandle
import (

View File

@ -8,10 +8,7 @@ import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/config"
"github.com/regclient/regclient/internal/sloghandle"
"github.com/regclient/regclient/internal/version"
"github.com/regclient/regclient/scheme"
"github.com/regclient/regclient/scheme/ocidir"
@ -174,14 +171,6 @@ func WithDockerCredsFile(fname string) Opt {
}
}
// WithLog configuring logging with a logrus Logger.
// Note that regclient has switched to log/slog for logging and my eventually deprecate logrus support.
func WithLog(log *logrus.Logger) Opt {
return func(rc *RegClient) {
rc.slog = slog.New(sloghandle.Logrus(log))
}
}
// WithRegOpts passes through opts to the reg scheme.
func WithRegOpts(opts ...reg.Opts) Opt {
return func(rc *RegClient) {

20
regclient_nowasm.go Normal file
View File

@ -0,0 +1,20 @@
//go:build !wasm
// +build !wasm
package regclient
import (
"log/slog"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/internal/sloghandle"
)
// WithLog configuring logging with a logrus Logger.
// Note that regclient has switched to log/slog for logging and my eventually deprecate logrus support.
func WithLog(log *logrus.Logger) Opt {
return func(rc *RegClient) {
rc.slog = slog.New(sloghandle.Logrus(log))
}
}

View File

@ -13,11 +13,8 @@ import (
"strings"
"sync"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/internal/pqueue"
"github.com/regclient/regclient/internal/reqmeta"
"github.com/regclient/regclient/internal/sloghandle"
"github.com/regclient/regclient/types/descriptor"
"github.com/regclient/regclient/types/errs"
"github.com/regclient/regclient/types/mediatype"
@ -83,14 +80,6 @@ func WithGC(gc bool) Opts {
}
}
// WithLog provides a logrus logger.
// By default logging is disabled.
func WithLog(log *logrus.Logger) Opts {
return func(c *ociConf) {
c.slog = slog.New(sloghandle.Logrus(log))
}
}
// WithSlog provides a slog logger.
// By default logging is disabled.
func WithSlog(slog *slog.Logger) Opts {

View File

@ -0,0 +1,20 @@
//go:build !wasm
// +build !wasm
package ocidir
import (
"log/slog"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/internal/sloghandle"
)
// WithLog provides a logrus logger.
// By default logging is disabled.
func WithLog(log *logrus.Logger) Opts {
return func(c *ociConf) {
c.slog = slog.New(sloghandle.Logrus(log))
}
}

View File

@ -7,14 +7,11 @@ import (
"sync"
"time"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/config"
"github.com/regclient/regclient/internal/cache"
"github.com/regclient/regclient/internal/pqueue"
"github.com/regclient/regclient/internal/reghttp"
"github.com/regclient/regclient/internal/reqmeta"
"github.com/regclient/regclient/internal/sloghandle"
"github.com/regclient/regclient/types/manifest"
"github.com/regclient/regclient/types/ref"
"github.com/regclient/regclient/types/referrer"
@ -237,14 +234,6 @@ func WithHTTPClient(hc *http.Client) Opts {
}
}
// WithLog injects a logrus Logger configuration
func WithLog(log *logrus.Logger) Opts {
return func(r *Reg) {
r.slog = slog.New(sloghandle.Logrus(log))
r.reghttpOpts = append(r.reghttpOpts, reghttp.WithLog(r.slog))
}
}
// WithManifestMax sets the push and pull limits for manifests
func WithManifestMax(push, pull int64) Opts {
return func(r *Reg) {

21
scheme/reg/reg_nowasm.go Normal file
View File

@ -0,0 +1,21 @@
//go:build !wasm
// +build !wasm
package reg
import (
"log/slog"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/internal/reghttp"
"github.com/regclient/regclient/internal/sloghandle"
)
// WithLog injects a logrus Logger configuration
func WithLog(log *logrus.Logger) Opts {
return func(r *Reg) {
r.slog = slog.New(sloghandle.Logrus(log))
r.reghttpOpts = append(r.reghttpOpts, reghttp.WithLog(r.slog))
}
}