Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove clog's singleton hook #67

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions clog/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ func (suite *BuilderUnitSuite) TestBuilder() {
return Ctx(ctx)
},
},
{
name: "singleton",
init: func(ctx context.Context) context.Context {
return Init(
ctx,
Settings{}.EnsureDefaults())
},
bldr: func(ctx context.Context) *builder {
return Singleton()
},
},
{
name: "singleton, no prior init",
init: func(ctx context.Context) context.Context {
return ctx
},
bldr: func(ctx context.Context) *builder {
return Singleton()
},
},
}

for _, test := range table {
Expand Down
20 changes: 0 additions & 20 deletions clog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,6 @@ func CtxErr(ctx context.Context, err error) *builder {
return nb
}

// Singleton is a shorthand for .Ctx(context.Background()). IE: it'll use the singleton
// logger directly; building one if necessary. You should avoid this and use .Ctx or
// .CtxErr if possible. Likelihood is that you're somewhere deep in a func chain that
// doesn't accept a ctx, and you still want to add a quick log; maybe for debugging purposes.
//
// That's fine! Everything should work great.
//
// Unless you call this before initialization. Then it'll panic. We do want you to init
// the logger first, else you'll potentially lose these logs due different buffers.
func Singleton() *builder {
if cloggerton == nil {
panic(clues.New("clog singleton requires prior initialization"))
}

return &builder{
ctx: context.Background(),
zsl: cloggerton.zsl,
}
}

// Flush writes out all buffered logs.
// Probably good to do before shutting down whatever instance
// had initialized the singleton.
Expand Down
Loading