chore(event): Reduce log noise for tests
This silences error messages when:
- There is no eventer in the context.Context
- There is no SysEventer
- And a new env var is set
Previously when the first two conditions where met, the error was logged
to a default hclog.Logger with the error being wrapped in a message to
note the lack of an eventer. In production this is a very important
message to help operators fix a likely misconfiguration. However, in
tests it is common to not have an eventer setup, meaning this generates
a lot of noise. This uses the CI environment variable which is an
environment variable set by most common CI environments. Developers can
set this variable locally to reduce the log noise:
export CI=true
See:
https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
This commit is contained in:
1 file changed
+11
-2
@@ -3,12 +3,15 @@ package event
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
var ci bool
|
||||
|
||||
type key int
|
||||
|
||||
const cancelledSendTimeout = 3 * time.Second
|
||||
@@ -18,6 +21,10 @@ const (
|
||||
requestInfoKey
|
||||
)
|
||||
|
||||
func init() {
|
||||
ci = os.Getenv("CI") != ""
|
||||
}
|
||||
|
||||
// NewEventerContext will return a context containing a value of the provided Eventer
|
||||
func NewEventerContext(ctx context.Context, eventer *Eventer) (context.Context, error) {
|
||||
const op = "event.NewEventerContext"
|
||||
@@ -128,8 +135,10 @@ func WriteError(ctx context.Context, caller Op, e error, opt ...Option) {
|
||||
if !ok {
|
||||
eventer = SysEventer()
|
||||
if eventer == nil {
|
||||
logger := hclog.New(nil)
|
||||
logger.Error(fmt.Sprintf("%s: no eventer available to write error: %v", op, e))
|
||||
if !ci {
|
||||
logger := hclog.New(nil)
|
||||
logger.Error(fmt.Sprintf("%s: no eventer available to write error: %v", op, e))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user