Skip to content

Commit 040565e

Browse files
authored
chore: change logging defaults (#27)
* change logging defaults * void gin logs differently
1 parent 09512bc commit 040565e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ preventing the need for network calls.
1717
The HTTP server mode is a 1:1 replacement for the Bucketing API used by all SDKs in cloud bucketing mode, or can be used
1818
directly without an SDK as an API.
1919

20+
Logging can be configured to write to a file for both application logs, and HTTP access logs; or just writing application
21+
logs to `stdout`. By default, the application logs are written to `stdout`, and the HTTP logs are written to `/dev/null`.
22+
2023
### Docker
2124

2225
The docker image published here is the base runtime version - expecting to be used as a base image for you to extend.

proxy.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"github.com/devcyclehq/go-server-sdk/v2/api"
66
"github.com/launchdarkly/eventsource"
7-
"io"
87
"log"
98
"os"
109
"strconv"
@@ -16,14 +15,17 @@ import (
1615

1716
func NewBucketingProxyInstance(instance *ProxyInstance) (*ProxyInstance, error) {
1817
gin.DisableConsoleColor()
19-
logFile, err := os.OpenFile(instance.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
20-
if err != nil {
21-
_ = fmt.Errorf("error opening log file: %s", err)
22-
return nil, err
18+
if instance.LogFile != "" {
19+
logFile, err := os.OpenFile(instance.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
20+
if err != nil {
21+
_ = fmt.Errorf("error opening log file: %s", err)
22+
return nil, err
23+
}
24+
gin.DefaultWriter = logFile
25+
log.SetOutput(logFile)
26+
} else {
27+
log.SetOutput(os.Stdout)
2328
}
24-
mw := io.MultiWriter(os.Stdout, logFile)
25-
log.SetOutput(mw)
26-
gin.DefaultWriter = mw
2729
if instance.SSEEnabled {
2830
instance.sseEvents = make(chan api.ClientEvent, 100)
2931
instance.sseServer = eventsource.NewServer()
@@ -100,7 +102,9 @@ func sdkProxyMiddleware(instance *ProxyInstance) gin.HandlerFunc {
100102
func newRouter(client *devcycle.Client, instance *ProxyInstance) *gin.Engine {
101103
r := gin.New()
102104

103-
r.Use(gin.Logger())
105+
if instance.LogFile != "" {
106+
r.Use(gin.Logger())
107+
}
104108
r.Use(gin.Recovery())
105109
r.Use(devCycleMiddleware(client))
106110
r.Use(sdkProxyMiddleware(instance))

0 commit comments

Comments
 (0)