Skip to content

Commit

Permalink
decode workload log before writing to cloud logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieqliu committed Oct 11, 2024
1 parent 0a70507 commit 6a11024
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions launcher/internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package logging

import (
"context"
"encoding/base64"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -211,9 +212,16 @@ func (l *logger) Error(msg string, args ...any) {
l.writeLog(clogging.Error, msg, args...)
}

// Write writes the given data to cloud logging. Implements the Writer interface for logging redirection.
func (l *logger) Write(p []byte) (n int, err error) {
pl := payload{payloadMessageKey: p}
// Write implements the Writer interface for workload logging redirection.
func (l *logger) Write(p []byte) (int, error) {
// Base64 decode input.
var decodedMessage []byte
_, err := base64.RawStdEncoding.Decode(decodedMessage, p)
if err != nil {
return 0, fmt.Errorf("error decoding message for cloud logging: %v", err)
}

pl := payload{payloadMessageKey: decodedMessage}

if len(l.instanceName) > 0 {
pl[payloadInstanceNameKey] = l.instanceName
Expand Down

0 comments on commit 6a11024

Please sign in to comment.