@@ -53,6 +53,7 @@ const (
53
53
UpgradeVolume = "UPGRADE_VOLUME"
54
54
UpgradeLockFileName = "UPGRADE_LOCK_FILENAME"
55
55
LogToJSON = "LOG_TO_JSON"
56
+ LogAPIRequests = "LOG_API_REQUESTS" // Defaults to true
56
57
VCapApplication = "VCAP_APPLICATION"
57
58
defaultSessionSecret = "wheeee!"
58
59
)
@@ -142,7 +143,7 @@ func main() {
142
143
143
144
if isUpgrading {
144
145
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 )
146
147
}
147
148
// Grab the Console Version from the executable
148
149
portalConfig .ConsoleVersion = appVersion
@@ -346,7 +347,7 @@ func main() {
346
347
portalProxy .StoreDiagnostics ()
347
348
348
349
// 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 {
350
351
log .Fatalf ("Unable to start: %v" , err )
351
352
}
352
353
log .Info ("Unable to start Stratos JetStream backend" )
@@ -728,7 +729,7 @@ func echoShouldNotLog(ec echo.Context) bool {
728
729
return false
729
730
}
730
731
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 {
732
733
log .Debug ("start" )
733
734
e := echo .New ()
734
735
e .HideBanner = true
@@ -738,14 +739,24 @@ func start(config interfaces.PortalConfig, p *portalProxy, needSetupMiddleware b
738
739
if ! isUpgrade {
739
740
e .Use (sessionCleanupMiddleware )
740
741
}
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" )
745
758
}
746
- customLoggerConfig .Skipper = echoShouldNotLog
747
759
748
- e .Use (middleware .LoggerWithConfig (customLoggerConfig ))
749
760
e .Use (middleware .Recover ())
750
761
e .Use (middleware .CORSWithConfig (middleware.CORSConfig {
751
762
AllowOrigins : config .AllowedOrigins ,
0 commit comments