-func (l *Logger) acquireLockConsiderWriting() {
- l.lock.Lock()
- if l.modified && l.writeAllowedNow() {
- // We have something new to write and we're allowed to write.
- l.write()
+ // Run all our hooks
+ for _, hook := range l.writeHooks {
+ hook(l.properties, l.entry)
+ }
+
+ // Update the event type.
+ if isFinal {
+ l.entry["event_type"] = l.params.EventTypePrefix + finalSuffix
+ } else if l.hasWritten {
+ l.entry["event_type"] = l.params.EventTypePrefix + partialSuffix
+ } else {
+ l.entry["event_type"] = l.params.EventTypePrefix + startSuffix
+ }
+ l.hasWritten = true
+
+ // Write the log entry.
+ // This is a network write and will take a while, which is bad
+ // because we're blocking all the other work on this goroutine.
+ //
+ // TODO(misha): Consider rewriting this so that we can encode l.data
+ // into a string, and then perform the actual write in another
+ // routine. This will be tricky and will require support in the
+ // client.
+ err := l.params.Client.Create("logs", l.data, nil)
+ if err != nil {
+ log.Printf("Received error writing %v: %v", l.data, err)