7710: update crunchrunner.upload.go to compile; this was broken after the keep-web...
[arvados.git] / sdk / go / logger / logger.go
index ce18e90ecfc3ac3134f997caf4634be74b9a0fa5..3b2db3a321271495a3965759363e2d723ea9e082 100644 (file)
 //     entry map[string]interface{}) {
 //   // Modifiy properties and entry however you want
 //   // properties is a shortcut for entry["properties"].(map[string]interface{})
-//   // properties can take any values you want to give it,
-//   // entry will only take the fields listed at http://doc.arvados.org/api/schema/Log.html
+//   // properties can take any (valid) values you want to give it,
+//   // entry will only take the fields listed at
+//   // http://doc.arvados.org/api/schema/Log.html
+//   // Valid values for properties are anything that can be json
+//   // encoded (i.e. will not error if you call json.Marshal() on it.
 // })
 package logger
 
 import (
+       "fmt"
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
        "log"
        "time"
@@ -70,16 +74,18 @@ type Logger struct {
 }
 
 // Create a new logger based on the specified parameters.
-func NewLogger(params LoggerParams) *Logger {
+func NewLogger(params LoggerParams) (l *Logger, err error) {
        // sanity check parameters
        if &params.Client == nil {
-               log.Fatal("Nil arvados client in LoggerParams passed in to NewLogger()")
+               err = fmt.Errorf("Nil arvados client in LoggerParams passed in to NewLogger()")
+               return
        }
        if params.EventTypePrefix == "" {
-               log.Fatal("Empty event type prefix in LoggerParams passed in to NewLogger()")
+               err = fmt.Errorf("Empty event type prefix in LoggerParams passed in to NewLogger()")
+               return
        }
 
-       l := &Logger{
+       l = &Logger{
                data:        make(map[string]interface{}),
                entry:       make(map[string]interface{}),
                properties:  make(map[string]interface{}),
@@ -94,7 +100,7 @@ func NewLogger(params LoggerParams) *Logger {
        // Start the worker goroutine.
        go l.work()
 
-       return l
+       return l, nil
 }
 
 // Exported functions will be called from other goroutines, therefore
@@ -193,7 +199,6 @@ func (l *Logger) write(isFinal bool) {
        // client.
        err := l.params.Client.Create("logs", l.data, nil)
        if err != nil {
-               log.Printf("Attempted to log: %v", l.data)
-               log.Fatalf("Received error writing log: %v", err)
+               log.Printf("Received error writing %v: %v", l.data, err)
        }
 }