github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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  	// Logf is called directly, rather than Infof so that the caller of Audit is
    29  	// recorded, not Audit itself.
    30  	logger.Logf(loggo.INFO, fmt.Sprintf("%s: %s", user.Tag(), format), args...)
    31  }