Skip to content

Commit

Permalink
Add a routine to parse GCP logging URIs.
Browse files Browse the repository at this point in the history
* This will help with registering sinks.
  • Loading branch information
jlewi committed May 4, 2024
1 parent 6ebc0e1 commit d19dfa0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/gorilla/mux v1.8.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/jlewi/monogo v0.0.0-20240123191147-401afe194d74
github.com/jlewi/monogo v0.0.0-20240504194504-63d901f32136
github.com/jlewi/p22h/backend v0.0.0-20220627190823-9107137fbd82
github.com/palantir/go-githubapp v0.16.0
github.com/spf13/viper v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jlewi/monogo v0.0.0-20240123191147-401afe194d74 h1:pbOw/rOMs0AZ494bGnI6DieGKwqoJQEjHWaJZrvxsJo=
github.com/jlewi/monogo v0.0.0-20240123191147-401afe194d74/go.mod h1:4QWrn/wb+L6rHHO3u5N250qJYWaZlHn1a8tFuWhZCP8=
github.com/jlewi/monogo v0.0.0-20240504194504-63d901f32136 h1:LS+T7H4fR+Et6wlu8WMCiAbNRQLSmIAUA3kL+7hsixk=
github.com/jlewi/monogo v0.0.0-20240504194504-63d901f32136/go.mod h1:s3nTD+owHZ6b+F13JdSpXLtrAH35pOqdwdcZEZ/gwBc=
github.com/jlewi/p22h/backend v0.0.0-20220627190823-9107137fbd82 h1:RPy3iuJyBD3dU0Kg5XCk0EDiY5qHhikPlbHi350K1Aw=
github.com/jlewi/p22h/backend v0.0.0-20220627190823-9107137fbd82/go.mod h1:JiaOBomo8HT5rxx+0Z5/18F/s4NN5qrDBA/+iRC6OGg=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
Expand Down
9 changes: 7 additions & 2 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/jlewi/hydros/pkg/gitops"
"github.com/jlewi/hydros/pkg/images"
"github.com/jlewi/hydros/pkg/util"
"github.com/jlewi/monogo/gcp/logging"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -66,10 +67,14 @@ func (a *App) SetupLogging() error {

// Use the keys used by cloud logging
// https://cloud.google.com/logging/docs/structured-logging
c.EncoderConfig.LevelKey = "severity"
c.EncoderConfig.TimeKey = "time"
c.EncoderConfig.LevelKey = logging.SeverityField
c.EncoderConfig.TimeKey = logging.TimeField
c.EncoderConfig.MessageKey = "message"

if len(cfg.Logging.OutputPaths) > 0 {
c.OutputPaths = cfg.Logging.OutputPaths
}

lvl := cfg.GetLogLevel()
zapLvl := zap.NewAtomicLevel()

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type Config struct {

type Logging struct {
Level string `json:"level,omitempty" yaml:"level,omitempty"`
// OutputPath is a list of paths to write logs to.
// Use stderr to write to stderr.
// Use gcplogs:///projects/${PROJECT}/logs/${LOGNAME} to write to Google Cloud Logging
OutputPaths []string `json:"outputPaths,omitempty" yaml:"outputPaths,omitempty"`
}

type GitHubConfig struct {
Expand Down

0 comments on commit d19dfa0

Please sign in to comment.