1package analytics 2 3import ( 4 "log" 5 "os" 6) 7 8// Instances of types implementing this interface can be used to define where 9// the analytics client logs are written. 10type Logger interface { 11 12 // Analytics clients call this method to log regular messages about the 13 // operations they perform. 14 // Messages logged by this method are usually tagged with an `INFO` log 15 // level in common logging libraries. 16 Logf(format string, args ...interface{}) 17 18 // Analytics clients call this method to log errors they encounter while 19 // sending events to the backend servers. 20 // Messages logged by this method are usually tagged with an `ERROR` log 21 // level in common logging libraries. 22 Errorf(format string, args ...interface{}) 23} 24 25// This function instantiate an object that statisfies the analytics.Logger 26// interface and send logs to standard logger passed as argument. 27func StdLogger(logger *log.Logger) Logger { 28 return stdLogger{ 29 logger: logger, 30 } 31} 32 33type stdLogger struct { 34 logger *log.Logger 35} 36 37func (l stdLogger) Logf(format string, args ...interface{}) { 38 l.logger.Printf("INFO: "+format, args...) 39} 40 41func (l stdLogger) Errorf(format string, args ...interface{}) { 42 l.logger.Printf("ERROR: "+format, args...) 43} 44 45func newDefaultLogger() Logger { 46 return StdLogger(log.New(os.Stderr, "rudder ", log.LstdFlags)) 47} 48