Add Discard Logger

For situations where we don't want any logs produced by the application.

* Remove references to Logger from README
* Add implementation of DiscardLogger
This commit is contained in:
Harlow Ward 2015-05-22 23:38:06 -07:00
parent ff1cff0293
commit bde3e96ad9
4 changed files with 31 additions and 21 deletions

View file

@ -42,8 +42,6 @@ package main
import (
"fmt"
"log"
"net/http"
"os"
"code.google.com/p/gcfg"
@ -75,7 +73,7 @@ func newS3Pipeline(cfg Config) *connector.Pipeline {
AppName: cfg.Pipeline.Name,
StreamName: cfg.Kinesis.StreamName,
}
e := &connector.S3ManifestEmitter{
e := &connector.S3Emitter{
S3Bucket: cfg.S3.BucketName,
}
return &connector.Pipeline{
@ -83,7 +81,6 @@ func newS3Pipeline(cfg Config) *connector.Pipeline {
Checkpoint: c,
Emitter: e,
Filter: f,
Logger: log.New(os.Stdout, "KINESIS: ", log.Ldate|log.Ltime|log.Lshortfile),
StreamName: cfg.Kinesis.StreamName,
Transformer: t,
}
@ -94,19 +91,16 @@ func main() {
var cfg Config
err := gcfg.ReadFileInto(&cfg, "pipeline.cfg")
// Set up kinesis client
// Set up kinesis client and stream
accessKey := os.Getenv("AWS_ACCESS_KEY")
secretKey := os.Getenv("AWS_SECRET_KEY")
ksis := kinesis.New(accessKey, secretKey, kinesis.Region{})
// Create and wait for streams
connector.CreateStream(ksis, cfg.Kinesis.StreamName, cfg.Kinesis.ShardCount)
// Fetch stream info
args := kinesis.NewArgs()
args.Add("StreamName", cfg.Kinesis.StreamName)
streamInfo, err := ksis.DescribeStream(args)
if err != nil {
fmt.Printf("Unable to connect to %s stream. Aborting.", cfg.Kinesis.StreamName)
return

View file

@ -2,25 +2,20 @@ package connector
import "log"
// the default implementation for a logger
// for this package.
type DefaultLogger struct {
}
// DefaultLogger is an implementation for std lib logger.
type DefaultLogger struct{}
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func (l *DefaultLogger) Fatalf(format string, v ...interface{}) {
log.Fatalf(format, v...)
}
// Printf calls Output to print to the standard logger. Arguments are
// handled in the manner of fmt.Printf.
func (l *DefaultLogger) Printf(format string, v ...interface{}) {
log.Printf(format, v...)
}
// make sure that there is a default logger instance
// initialized, so that we don't end up with panics
// Make sure that there is a default logger instance initialized, so
// that we don't end up with panics.
var logger Logger = &DefaultLogger{}
// expose the ability to change the logger so that
// external packages can control the logging for
// this package
func SetLogger(l Logger) {
logger = l
}

15
discard_logger.go Normal file
View file

@ -0,0 +1,15 @@
package connector
import "os"
// DiscardLogger is the an implementation of a Logger that does not
// send any output. It can be used in scenarios when logging is not desired.
type DiscardLogger struct{}
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func (l *DiscardLogger) Fatalf(format string, v ...interface{}) {
os.Exit(1)
}
// Printf is noop and does not have any output.
func (l *DiscardLogger) Printf(format string, v ...interface{}) {}

View file

@ -6,3 +6,9 @@ type Logger interface {
Fatalf(format string, v ...interface{})
Printf(format string, v ...interface{})
}
// SetLogger adds the ability to change the logger so that external packages
// can control the logging for this package
func SetLogger(l Logger) {
logger = l
}