From 6ca2abb7f8dbc00ab4052a3fd23e5f155e4f80f2 Mon Sep 17 00:00:00 2001 From: Harlow Ward Date: Sat, 23 May 2015 11:40:04 -0700 Subject: [PATCH] User Log package for default logger * Modify the default logger to it also logs Line Numbers * Update README w/ logging instructions --- README.md | 21 +++++++++++++++++---- default_logger.go | 21 --------------------- logger.go | 8 ++++++++ 3 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 default_logger.go diff --git a/README.md b/README.md index 8a4579c..dec4c06 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,25 @@ Install the library: $ go get github.com/harlow/kinesis-connectors -### Example S3 Pipeline +### Logging -The S3 Pipeline performs the following steps: +Default logging is handled by Package log. An application can override the defualt package logging by +changing it's `logger` variable: -1. Pull records from Kinesis and buffer them untill the desired threshold is reached. -2. Upload the records to an S3 bucket. +```go +connector.SetLogger(NewCustomLogger()) +``` + +The customer logger must implement the [Logger interface][log_interface]. + +[log_interface]: https://github.com/harlow/kinesis-connectors/blob/master/logger.go + +### Example Pipeline + +The S3 Connector Pipeline performs the following steps: + +1. Pull records from Kinesis and buffer them untill the desired threshold is met. +2. Upload the batch of records to an S3 bucket. 3. Set the current Shard checkpoint in Redis. The config vars are loaded done with [gcfg]. diff --git a/default_logger.go b/default_logger.go deleted file mode 100644 index 1825723..0000000 --- a/default_logger.go +++ /dev/null @@ -1,21 +0,0 @@ -package connector - -import "log" - -// 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. -var logger Logger = &DefaultLogger{} diff --git a/logger.go b/logger.go index 103f023..9317c06 100644 --- a/logger.go +++ b/logger.go @@ -1,5 +1,10 @@ package connector +import ( + "log" + "os" +) + // Logger sends pipeline info and errors to logging endpoint. The logger could be // used to send to STDOUT, Syslog, or any number of distributed log collecting platforms. type Logger interface { @@ -7,6 +12,9 @@ type Logger interface { Printf(format string, v ...interface{}) } +// specify a default logger so that we don't end up with panics. +var logger Logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) + // SetLogger adds the ability to change the logger so that external packages // can control the logging for this package func SetLogger(l Logger) {