Skip to content

Commit

Permalink
use logz.VerboseContext now.
Browse files Browse the repository at this point in the history
to enable visibilities of cmdr internal logger outputs, run your app with this form:

```bash
go run -tags=verbose ./main.go
go build -tags=verbose -o my-app ./main.go
```
  • Loading branch information
hedzr committed Oct 21, 2024
1 parent 466b033 commit 17a7b54
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion builder/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *appS) Args() []string { return s.args }
func (s *appS) Build() {
if sr, ok := s.Runner.(setRoot); ok {
ctx := context.Background()
logz.DebugContext(ctx, "builder.appS.Build() - setRoot")
logz.VerboseContext(ctx, "builder.appS.Build() - setRoot")
if cx, ok := s.root.Cmd.(*cli.CmdS); ok {
cx.EnsureTree(ctx, s, s.root)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (c *CmdS) getDeferAction(ctx context.Context, cmd Cmd, args []string) func(
// This function will be called for running time once (see also cmdr.Run()).
func (c *CmdS) EnsureTree(ctx context.Context, app App, root *RootCommand) {
if atomic.CompareAndSwapInt32(&root.linked, 0, 1) {
logz.DebugContext(ctx, "cmd.EnsureTree (Once) -> linking to root and owner", "root", root)
logz.VerboseContext(ctx, "cmd.EnsureTree (Once) -> linking to root and owner", "root", root)
c.ensureTreeAlways(ctx, app, root)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func (w *workerS) exec(ctx context.Context, pc *parseCtx) (err error) {
w.parsingCtx = pc // save pc for later, OnAction might need it.
lastCmd := pc.LastCmd()
logz.DebugContext(ctx, "[cmdr] exec...", "last-matched-cmd", lastCmd)
logz.VerboseContext(ctx, "[cmdr] exec...", "last-matched-cmd", lastCmd)

forceDefaultAction := pc.forceDefaultAction

Expand Down
4 changes: 2 additions & 2 deletions cli/worker/pre.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

func (w *workerS) preProcess(ctx context.Context) (err error) {
// w.Config.Store.Load() // from external providers: 1. consul, 2. local,
logz.DebugContext(ctx, "pre-processing...")
logz.VerboseContext(ctx, "pre-processing...")
dummyParseCtx := parseCtx{root: w.root, forceDefaultAction: w.ForceDefaultAction}

w.preEnvSet(ctx) // setup envvars: APP, APP_NAME, etc.
Expand Down Expand Up @@ -275,7 +275,7 @@ func (w *workerS) xrefCommands(ctx context.Context, root *cli.RootCommand, cb ..
// }

func (w *workerS) postProcess(ctx context.Context, pc *parseCtx) (err error) {
logz.DebugContext(ctx, "post-processing...")
logz.VerboseContext(ctx, "post-processing...")
_, _ = pc, ctx
return
}
4 changes: 2 additions & 2 deletions cli/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ func (w *workerS) InitGlobally(ctx context.Context) {
func (w *workerS) initGlobalResources() {
defer w.triggerGlobalResourcesInitOK()
ctx := context.Background()
logz.DebugContext(ctx, "workerS.initGlobalResources")
logz.VerboseContext(ctx, "workerS.initGlobalResources")

// to do sth...
}

func (w *workerS) triggerGlobalResourcesInitOK() {
// to do sth...
ctx := context.Background()
logz.DebugContext(ctx, "workerS.triggerGlobalResourcesInitOK")
logz.VerboseContext(ctx, "workerS.triggerGlobalResourcesInitOK")
}

func (w *workerS) attachErrors(errs ...error) { //nolint:revive,unused
Expand Down

0 comments on commit 17a7b54

Please sign in to comment.