Skip to content

Commit acd9ef7

Browse files
authored
Merge pull request #64 from cortexapps/shawn/logging-production-json
Support structured (JSON) logging in prod env
2 parents 21e4121 + bd04505 commit acd9ef7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.vscode/launch.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"request": "launch",
1313
"mode": "auto",
1414
"program": "${workspaceFolder}/agent/main.go",
15+
"env": {
16+
"ENV": "dev"
17+
},
1518
"args": [
1619
"serve",
1720
"--dry-run",
@@ -28,7 +31,10 @@
2831
"serve",
2932
"-v"
3033
],
31-
"envFile": "${workspaceFolder}/.env"
34+
"envFile": "${workspaceFolder}/.env",
35+
"env": {
36+
// "ENV": "production",
37+
}
3238
},
3339
{
3440
"name": "Launch Python SDK Example",

agent/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func init() {
1818
rootCmd.AddCommand(handlersRootCmd)
1919
rootCmd.AddCommand(RelayCommand)
2020

21-
rootCmd.Flags().BoolP("verbose", "v", false, "Verbose mode")
21+
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Verbose mode")
2222
}
2323

2424
func Execute() {

agent/cmd/stack.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import (
1111
cortexHttp "github.com/cortexapps/axon/server/http"
1212
"github.com/spf13/cobra"
1313
"go.uber.org/fx"
14+
"go.uber.org/fx/fxevent"
1415
"go.uber.org/zap"
1516
)
1617

1718
func startAgent(opts fx.Option) {
1819
app := fx.New(
1920
opts,
21+
fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
22+
return &fxevent.ZapLogger{Logger: logger}
23+
}),
2024
)
2125

2226
noBanner := os.Getenv("NO_BANNER")
@@ -30,6 +34,9 @@ var AgentModule = fx.Module("agent",
3034
fx.Provide(func(config config.AgentConfig) *zap.Logger {
3135

3236
cfg := zap.NewDevelopmentConfig()
37+
if os.Getenv("ENV") == "production" {
38+
cfg = zap.NewProductionConfig()
39+
}
3340

3441
loggingLevel := zap.InfoLevel
3542
if config.VerboseOutput {

0 commit comments

Comments
 (0)