~themue/juju-core/go-provisioning-test-fix

« back to all changes in this revision

Viewing changes to juju/log.go

  • Committer: Mathieu Lonjaret
  • Date: 2011-12-01 15:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: mathieu.lonjaret@gmail.com-20111201153758-0a0kkibpl6pge2ie
logger: use global vars, becomes a package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package juju
2
 
 
3
 
import "fmt"
4
 
 
5
 
type Logger interface {
6
 
        Output(calldepth int, s string) error
7
 
}
8
 
 
9
 
var globalLogger Logger
10
 
var globalDebug bool
11
 
 
12
 
const (
13
 
        logPrefix = "JUJU "
14
 
        dbgPrefix = "JUJU:DEBUG "
15
 
)
16
 
 
17
 
// Specify the *log.Logger object where log messages should be sent to.
18
 
func SetLogger(logger Logger) {
19
 
        globalLogger = logger
20
 
}
21
 
 
22
 
// Enable the delivery of debug messages to the logger.  Only meaningful
23
 
// if a logger is also set.
24
 
func SetDebug(debug bool) {
25
 
        globalDebug = debug
26
 
}
27
 
 
28
 
// Logf logs the formatted message onto the Logger set via SetLogger.
29
 
func Logf(format string, v ...interface{}) {
30
 
        if globalLogger != nil {
31
 
                globalLogger.Output(2, logPrefix+fmt.Sprintf(format, v...))
32
 
        }
33
 
}
34
 
 
35
 
// Debugf logs the formatted message onto the Logger set via SetLogger,
36
 
// as long as debugging was enabled with SetDebug.
37
 
func Debugf(format string, v ...interface{}) {
38
 
        if globalDebug && globalLogger != nil {
39
 
                globalLogger.Output(2, dbgPrefix+fmt.Sprintf(format, v...))
40
 
        }
41
 
}