Hi there,

When combining V() and ${Level}Depth() together, the logging logic becomes
less
clear. For instance, with the retry function below:

```go
func Retry(fn func() error) error {
  var lastErr error
  for attempt := 0; attempt < maxRetries; attempt++ {
    backoff.Sleep(attempt)
    if lastErr = fn(); lastErr == nil {
      return nil
    }
    // Determined by -vmodule set for retry().
    if glog.V(1) {
      // Using caller info at 1 level up in the call stack.
      glog.WarningDepth(1, fmt.Sprintf("Attempt %d failed: %v", attempt,
lastErr))
    }
  }
  if glog.V(1) {
    glog.WarningDepth(1, fmt.Sprintf("Exhausted %d retries: %v",
maxRetries, lastErr))
  }
  return lastErr
}
```

In this example, Retry() as a helper function, which performs backoff
retries of fn().
It logs in case fn() fails, but instead of logging with context of Retry()
function,
using the context of the Retry() caller will provide better insights for
debugging.

When use ${Level}Depth() with V(), I would expect the verbose status is
determined while
aware of the depth set. So that -vmodule set for the Retry() caller should
be used for
determine the return value of V().

I propose adding a function called `VDepth(level, depth)`, so that the user
may
hint which caller to use.

Best,
Xiaoyi

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to