github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/labix.org/v2/mgo/log.go (about) 1 // mgo - MongoDB driver for Go 2 // 3 // Copyright (c) 2010-2012 - Gustavo Niemeyer <gustavo@niemeyer.net> 4 // 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions are met: 9 // 10 // 1. Redistributions of source code must retain the above copyright notice, this 11 // list of conditions and the following disclaimer. 12 // 2. Redistributions in binary form must reproduce the above copyright notice, 13 // this list of conditions and the following disclaimer in the documentation 14 // and/or other materials provided with the distribution. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 package mgo 28 29 import "fmt" 30 31 // --------------------------------------------------------------------------- 32 // Logging integration. 33 34 // Avoid importing the log type information unnecessarily. There's a small cost 35 // associated with using an interface rather than the type. Depending on how 36 // often the logger is plugged in, it would be worth using the type instead. 37 type log_Logger interface { 38 Output(calldepth int, s string) error 39 } 40 41 var globalLogger log_Logger 42 var globalDebug bool 43 44 // Specify the *log.Logger object where log messages should be sent to. 45 func SetLogger(logger log_Logger) { 46 globalLogger = logger 47 } 48 49 // Enable the delivery of debug messages to the logger. Only meaningful 50 // if a logger is also set. 51 func SetDebug(debug bool) { 52 globalDebug = debug 53 } 54 55 func log(v ...interface{}) { 56 if globalLogger != nil { 57 globalLogger.Output(2, fmt.Sprint(v...)) 58 } 59 } 60 61 func logln(v ...interface{}) { 62 if globalLogger != nil { 63 globalLogger.Output(2, fmt.Sprintln(v...)) 64 } 65 } 66 67 func logf(format string, v ...interface{}) { 68 if globalLogger != nil { 69 globalLogger.Output(2, fmt.Sprintf(format, v...)) 70 } 71 } 72 73 func debug(v ...interface{}) { 74 if globalDebug && globalLogger != nil { 75 globalLogger.Output(2, fmt.Sprint(v...)) 76 } 77 } 78 79 func debugln(v ...interface{}) { 80 if globalDebug && globalLogger != nil { 81 globalLogger.Output(2, fmt.Sprintln(v...)) 82 } 83 } 84 85 func debugf(format string, v ...interface{}) { 86 if globalDebug && globalLogger != nil { 87 globalLogger.Output(2, fmt.Sprintf(format, v...)) 88 } 89 }