github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/utils/logging.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package utils
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/loggo"
     9  	"github.com/juju/utils/featureflag"
    10  
    11  	"github.com/juju/juju/feature"
    12  )
    13  
    14  var logger = loggo.GetLogger("juju.utils")
    15  
    16  // LoggedErrorStack is a developer helper function that will cause the error
    17  // stack of the error to be printed out at error severity if and only if the
    18  // "log-error-stack" feature flag has been specified.  The passed in error
    19  // is also the return value of this function.
    20  func LoggedErrorStack(err error) error {
    21  	if featureflag.Enabled(feature.LogErrorStack) {
    22  		logger.Errorf("error stack:\n%s", errors.ErrorStack(err))
    23  	}
    24  	return err
    25  }