Skip to content

Commit 2b94989

Browse files
authored
Optionally disable api logging (#4144)
* Ensure for maxed lists we don't make requests for pages after one - Missing return meant we still fetched remaining pages - This means lists are marked as busy until all pages are fetched, even though the list is displayed as maxed * Optionally Log API Requests to Jetstream - Defaults to true - Set env var LOG_API_REQUESTS != "true" to disable
1 parent 92b71ed commit 2b94989

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/jetstream/default.config.properties

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SQLITE_KEEP_DB=true
2222
UI_PATH=../../dist
2323

2424
LOG_TO_JSON=false
25+
LOG_API_REQUESTS=true
2526

2627
SSO_LOGIN=false
2728
SSO_WHITELIST=

src/jetstream/main.go

+20-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
UpgradeVolume = "UPGRADE_VOLUME"
5454
UpgradeLockFileName = "UPGRADE_LOCK_FILENAME"
5555
LogToJSON = "LOG_TO_JSON"
56+
LogAPIRequests = "LOG_API_REQUESTS" // Defaults to true
5657
VCapApplication = "VCAP_APPLICATION"
5758
defaultSessionSecret = "wheeee!"
5859
)
@@ -142,7 +143,7 @@ func main() {
142143

143144
if isUpgrading {
144145
log.Info("Upgrade in progress (lock file detected) ... waiting for lock file to be removed ...")
145-
start(portalConfig, &portalProxy{env: envLookup}, false, true)
146+
start(portalConfig, &portalProxy{env: envLookup}, false, true, envLookup)
146147
}
147148
// Grab the Console Version from the executable
148149
portalConfig.ConsoleVersion = appVersion
@@ -346,7 +347,7 @@ func main() {
346347
portalProxy.StoreDiagnostics()
347348

348349
// Start the back-end
349-
if err := start(portalProxy.Config, portalProxy, needSetupMiddleware, false); err != nil {
350+
if err := start(portalProxy.Config, portalProxy, needSetupMiddleware, false, envLookup); err != nil {
350351
log.Fatalf("Unable to start: %v", err)
351352
}
352353
log.Info("Unable to start Stratos JetStream backend")
@@ -728,7 +729,7 @@ func echoShouldNotLog(ec echo.Context) bool {
728729
return false
729730
}
730731

731-
func start(config interfaces.PortalConfig, p *portalProxy, needSetupMiddleware bool, isUpgrade bool) error {
732+
func start(config interfaces.PortalConfig, p *portalProxy, needSetupMiddleware bool, isUpgrade bool, envLookup *env.VarSet) error {
732733
log.Debug("start")
733734
e := echo.New()
734735
e.HideBanner = true
@@ -738,14 +739,24 @@ func start(config interfaces.PortalConfig, p *portalProxy, needSetupMiddleware b
738739
if !isUpgrade {
739740
e.Use(sessionCleanupMiddleware)
740741
}
741-
customLoggerConfig := middleware.LoggerConfig{
742-
Format: `Request: [${time_rfc3339}] Remote-IP:"${remote_ip}" ` +
743-
`Method:"${method}" Path:"${path}" Status:${status} Latency:${latency_human} ` +
744-
`Bytes-In:${bytes_in} Bytes-Out:${bytes_out}` + "\n",
742+
743+
logAPIRequests := "true"
744+
if envLogAPIRequests, ok := envLookup.Lookup(LogAPIRequests); ok {
745+
logAPIRequests = envLogAPIRequests
746+
}
747+
if logAPIRequests == "true" {
748+
customLoggerConfig := middleware.LoggerConfig{
749+
Format: `Request: [${time_rfc3339}] Remote-IP:"${remote_ip}" ` +
750+
`Method:"${method}" Path:"${path}" Status:${status} Latency:${latency_human} ` +
751+
`Bytes-In:${bytes_in} Bytes-Out:${bytes_out}` + "\n",
752+
}
753+
customLoggerConfig.Skipper = echoShouldNotLog
754+
755+
e.Use(middleware.LoggerWithConfig(customLoggerConfig))
756+
} else {
757+
log.Warn("Disabled logging of API requests received by Jetstream")
745758
}
746-
customLoggerConfig.Skipper = echoShouldNotLog
747759

748-
e.Use(middleware.LoggerWithConfig(customLoggerConfig))
749760
e.Use(middleware.Recover())
750761
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
751762
AllowOrigins: config.AllowedOrigins,

0 commit comments

Comments
 (0)