govendor
This commit is contained in:
32
vendor/github.com/fluffle/goirc/logging/glog/glog.go
generated
vendored
Normal file
32
vendor/github.com/fluffle/goirc/logging/glog/glog.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package glog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/glog"
|
||||
"github.com/fluffle/goirc/logging"
|
||||
)
|
||||
|
||||
// Simple adapter to utilise Google's GLog package with goirc.
|
||||
// Just import this package alongside goirc/client and call
|
||||
// glog.Init() in your main() to set things up.
|
||||
type GLogger struct{}
|
||||
|
||||
func (gl GLogger) Debug(f string, a ...interface{}) {
|
||||
// GLog doesn't have a "Debug" level, so use V(2) instead.
|
||||
if glog.V(2) {
|
||||
glog.InfoDepth(3, fmt.Sprintf(f, a...))
|
||||
}
|
||||
}
|
||||
func (gl GLogger) Info(f string, a ...interface{}) {
|
||||
glog.InfoDepth(3, fmt.Sprintf(f, a...))
|
||||
}
|
||||
func (gl GLogger) Warn(f string, a ...interface{}) {
|
||||
glog.WarningDepth(3, fmt.Sprintf(f, a...))
|
||||
}
|
||||
func (gl GLogger) Error(f string, a ...interface{}) {
|
||||
glog.ErrorDepth(3, fmt.Sprintf(f, a...))
|
||||
}
|
||||
|
||||
func Init() {
|
||||
logging.SetLogger(GLogger{})
|
||||
}
|
||||
43
vendor/github.com/fluffle/goirc/logging/logging.go
generated
vendored
Normal file
43
vendor/github.com/fluffle/goirc/logging/logging.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package logging
|
||||
|
||||
// The IRC client will log things using these methods
|
||||
type Logger interface {
|
||||
// Debug logging of raw socket comms to/from server.
|
||||
Debug(format string, args ...interface{})
|
||||
// Informational logging about client behaviour.
|
||||
Info(format string, args ...interface{})
|
||||
// Warnings of inconsistent or unexpected data, mostly
|
||||
// related to state tracking of IRC nicks/chans.
|
||||
Warn(format string, args ...interface{})
|
||||
// Errors, mostly to do with network communication.
|
||||
Error(format string, args ...interface{})
|
||||
}
|
||||
|
||||
// By default we do no logging. Logging is enabled or disabled
|
||||
// at the package level, since I'm lazy and re-re-reorganising
|
||||
// my code to pass a per-client-struct Logger around to all the
|
||||
// state objects is a pain in the arse.
|
||||
var logger Logger = nullLogger{}
|
||||
|
||||
// SetLogger sets the internal goirc Logger to l. If l is nil,
|
||||
// a dummy logger that does nothing is installed instead.
|
||||
func SetLogger(l Logger) {
|
||||
if l == nil {
|
||||
logger = nullLogger{}
|
||||
} else {
|
||||
logger = l
|
||||
}
|
||||
}
|
||||
|
||||
// A nullLogger does nothing while fulfilling Logger.
|
||||
type nullLogger struct{}
|
||||
func (nl nullLogger) Debug(f string, a ...interface{}) {}
|
||||
func (nl nullLogger) Info(f string, a ...interface{}) {}
|
||||
func (nl nullLogger) Warn(f string, a ...interface{}) {}
|
||||
func (nl nullLogger) Error(f string, a ...interface{}) {}
|
||||
|
||||
// Shim functions so that the package can be used directly
|
||||
func Debug(f string, a ...interface{}) { logger.Debug(f, a...) }
|
||||
func Info(f string, a ...interface{}) { logger.Info(f, a...) }
|
||||
func Warn(f string, a ...interface{}) { logger.Warn(f, a...) }
|
||||
func Error(f string, a ...interface{}) { logger.Error(f, a...) }
|
||||
Reference in New Issue
Block a user