Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Set logger prefix to CLOUDPROBER_LOG_PREFIX env variable is available.
Browse files Browse the repository at this point in the history
In cloudprober_startup.sh pass all env variables starting with CLOUDPROBER_* to the container.

PiperOrigin-RevId: 238730895
  • Loading branch information
manugarg committed Mar 18, 2019
1 parent 3e2968b commit 482128e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions logger/logger.go
Expand Up @@ -36,11 +36,15 @@ import (

var (
debugLog = flag.Bool("debug_log", false, "Whether to output debug logs or not")

// LogPrefixEnvVar environment variable is used to determine the stackdriver
// log name prefix. Default prefix is "cloudprober".
LogPrefixEnvVar = "CLOUDPROBER_LOG_PREFIX"
)

const (
// Prefix for the cloudprober stackdriver log names.
cloudproberPrefix = "cloudprober."
cloudproberPrefix = "cloudprober"
)

const (
Expand All @@ -52,11 +56,11 @@ const (
MaxLogEntrySize = 4096
)

// Logger implements a logger that logs messages to Google Cloud Logging. It provides a suite
// of methods where each method correponds to a specific logging.Level, e.g.
// Error(paylod interface{}). Each method takes a payload that has to either be a
// JSON-encodable object, a string or a []byte slice (all other types of payload will result
// in error).
// Logger implements a logger that logs messages to Google Cloud Logging. It
// provides a suite of methods where each method corresponds to a specific
// logging.Level, e.g. Error(paylod interface{}). Each method takes a payload
// that has to either be a JSON-encodable object, a string or a []byte slice
// (all other types of payload will result in error).
//
// It falls back to logging through the traditional logger if:
//
Expand All @@ -78,7 +82,14 @@ type Logger struct {
// NewCloudproberLog is a convenient wrapper around New that sets context to
// context.Background and attaches cloudprober prefix to log names.
func NewCloudproberLog(component string) (*Logger, error) {
return New(context.Background(), cloudproberPrefix+component)
cpPrefix := cloudproberPrefix

envLogPrefix := os.Getenv(LogPrefixEnvVar)
if envLogPrefix != "" {
cpPrefix = envLogPrefix
}

return New(context.Background(), cpPrefix+"."+component)
}

// New returns a new Logger object with cloud logging client initialized if running on GCE.
Expand Down
2 changes: 1 addition & 1 deletion tools/cloudprober_startup.sh
Expand Up @@ -56,5 +56,5 @@ DIGEST=$(docker inspect --format "{{.Id}}" "${IMAGE}:${VERSION}")
VARS="kernel=${KERNEL_VERSION},google_release=${GOOGLE_RELEASE}"
VARS="${VARS},${JOB}_tag=${VERSION},${JOB}_version=${DIGEST:0:12}"

docker run -e "SYSVARS=${VARS}" -e "CLOUDPROBER_PORT=${CLOUDPROBER_PORT:-""}" \
docker run -e "SYSVARS=${VARS}" --env-file <(env | grep CLOUDPROBER_) \
--net host --privileged -v /tmp:/tmp "${IMAGE}:${VERSION}"

0 comments on commit 482128e

Please sign in to comment.