4e1366f285
Pipe http server log to hclog, so that it uses the same logging format as rest of nomad logs. Also, supports emitting them as json logs, when json formatting is set. The http server logs are emitted as Trace level, as they are typically repsent HTTP client errors (e.g. failed tls handshakes, invalid headers, etc). Though, Panic logs represent server errors and are relayed as Error level.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHttpServerLoggerFilters_Level_Info(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
hclogger := hclog.New(&hclog.LoggerOptions{
|
|
Name: "testlog",
|
|
Output: &buf,
|
|
Level: hclog.Info,
|
|
})
|
|
|
|
stdlogger := newHTTPServerLogger(hclogger)
|
|
|
|
// spurious logging would be filtered out
|
|
stdlogger.Printf("spurious logging: %v", "arg")
|
|
require.Empty(t, buf.String())
|
|
|
|
// panics are included
|
|
stdlogger.Printf("panic while processing: %v", "endpoint")
|
|
require.Contains(t, buf.String(), "[ERROR] testlog: panic while processing: endpoint")
|
|
|
|
}
|
|
|
|
func TestHttpServerLoggerFilters_Level_Trace(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
hclogger := hclog.New(&hclog.LoggerOptions{
|
|
Name: "testlog",
|
|
Output: &buf,
|
|
Level: hclog.Trace,
|
|
})
|
|
|
|
stdlogger := newHTTPServerLogger(hclogger)
|
|
|
|
// spurious logging will be included as Trace level
|
|
stdlogger.Printf("spurious logging: %v", "arg")
|
|
require.Contains(t, buf.String(), "[TRACE] testlog: spurious logging: arg")
|
|
|
|
stdlogger.Printf("panic while processing: %v", "endpoint")
|
|
require.Contains(t, buf.String(), "[ERROR] testlog: panic while processing: endpoint")
|
|
|
|
}
|