github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/audit/audit.go (about)

     1  // Copyright 2013, 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // Package audit records auditable events
     5  package audit
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/juju/loggo"
    11  )
    12  
    13  var logger = loggo.GetLogger("audit")
    14  
    15  // Tagger represents anything that implements a Tag method.
    16  type Tagger interface {
    17  	Tag() string
    18  }
    19  
    20  // Audit records an auditable event against the tagged entity that performed the action.
    21  func Audit(user Tagger, format string, args ...interface{}) {
    22  	if user == nil {
    23  		panic("user cannot be nil")
    24  	}
    25  	if user.Tag() == "" {
    26  		panic("user tag cannot be blank")
    27  	}
    28  
    29  	// LogCallf is called directly, rather than Infof so that the caller
    30  	// of Audit is recorded, not Audit itself.
    31  	// Also, we're using LogCallf instead of Logf to work around a bug
    32  	// in the go1.4 version of go vet (https://github.com/golang/go/issues/9080)
    33  	// which incorrectly flags the Logf call.
    34  	logger.LogCallf(1, loggo.INFO, fmt.Sprintf("%s: %s", user.Tag(), format), args...)
    35  }