User Log package for default logger

* Modify the default logger to it also logs Line Numbers
* Update README w/ logging instructions
This commit is contained in:
Harlow Ward 2015-05-23 11:40:04 -07:00
parent e52fcb4f8c
commit 6ca2abb7f8
3 changed files with 25 additions and 25 deletions

View file

@ -30,12 +30,25 @@ Install the library:
$ go get github.com/harlow/kinesis-connectors $ 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. ```go
2. Upload the records to an S3 bucket. 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. 3. Set the current Shard checkpoint in Redis.
The config vars are loaded done with [gcfg]. The config vars are loaded done with [gcfg].

View file

@ -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{}

View file

@ -1,5 +1,10 @@
package connector package connector
import (
"log"
"os"
)
// Logger sends pipeline info and errors to logging endpoint. The logger could be // 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. // used to send to STDOUT, Syslog, or any number of distributed log collecting platforms.
type Logger interface { type Logger interface {
@ -7,6 +12,9 @@ type Logger interface {
Printf(format string, v ...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 // SetLogger adds the ability to change the logger so that external packages
// can control the logging for this package // can control the logging for this package
func SetLogger(l Logger) { func SetLogger(l Logger) {