Skip to content

Commit

Permalink
Merge pull request #8 from saucelabs/alana-sc-3757-revert-standard-lo…
Browse files Browse the repository at this point in the history
…g-redirect

Revert standard log redirect
  • Loading branch information
waggledans authored Apr 18, 2022
2 parents 84dcb2b + 0b80b50 commit 0e2171b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 72 deletions.
30 changes: 0 additions & 30 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package logger

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -118,31 +116,3 @@ func (pL *ProxyLogger) Printf(format string, v ...interface{}) {
format = strings.TrimSpace(format)
pL.Logger.Debuglnf(format, v...)
}

type StandardLogger struct {
Logger *sypl.Sypl
}

// Write satisfies the standard logging interface. Default logging level will be
// `Debug`.
func (pL *StandardLogger) Write(p []byte) (int, error) {
p = bytes.TrimSpace(p)
pL.Logger.Debug(string(p))
return len(p), nil
}

// RedirectStandardLogs redirects logs created with the standard library global logger
// to the ProxyLogger.
func RedirectStandardLogs() {
log.SetFlags(0)
log.SetPrefix("")
standardLogger := &StandardLogger{
Logger: Get().New("go"),
}
log.SetOutput(standardLogger)
}

// DisableStandardLogs disables logs created with the standard library global logger
func DisableStandardLogs() {
log.SetOutput(ioutil.Discard)
}
37 changes: 0 additions & 37 deletions internal/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
package logger

import (
"log"
"strings"
"testing"

"github.com/saucelabs/sypl"
"github.com/saucelabs/sypl/level"
"github.com/saucelabs/sypl/output"
"github.com/saucelabs/sypl/processor"
"github.com/saucelabs/sypl/shared"
)

func TestSetup(t *testing.T) {
Expand Down Expand Up @@ -66,32 +58,3 @@ func TestSetup(t *testing.T) {
})
}
}


func TestRedirectStandardLogs(t *testing.T) {
// set global proxy logger
proxyLogger = sypl.NewDefault("test", level.Debug)
defer func(){proxyLogger = nil}()

// proxyLogger sends output to a buffer
buffer, outputBuffer := output.SafeBuffer(level.Trace, processor.PrefixBasedOnMask(shared.DefaultTimestampFormat))
proxyLogger.AddOutputs(outputBuffer)

// test standard logger before and after redirect
beforeMsg := "Before redirect"
afterMsg := "After redirect"
log.Println(beforeMsg)

RedirectStandardLogs()
log.Println(afterMsg)

bufferStr := buffer.String()

if strings.Contains(bufferStr, beforeMsg) {
t.Errorf("%s should not appear in proxy logger: %s", beforeMsg, bufferStr)
}
if !strings.Contains(bufferStr, afterMsg) {
t.Errorf("%s should appear in proxy logger: %s", afterMsg, bufferStr)
}

}
5 changes: 0 additions & 5 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,6 @@ func New(

proxy.Logger = proxyLogger
proxy.Verbose = true

// Ensure any standard log messages use a configured logger
logger.RedirectStandardLogs()
} else {
logger.DisableStandardLogs()
}

proxy.KeepDestinationHeaders = true
Expand Down

0 comments on commit 0e2171b

Please sign in to comment.