-
Notifications
You must be signed in to change notification settings - Fork 657
Expand file tree
/
Copy pathlogging_test.go
More file actions
56 lines (47 loc) · 1.45 KB
/
logging_test.go
File metadata and controls
56 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package observability
import (
"os"
"path/filepath"
"sync"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/supabase/auth/internal/conf"
)
func TestConfigureLoggingWithFile(t *testing.T) {
// loggingOnce must be reset for this branch to run; we can only do this
// safely from inside the package's own tests.
loggingOnce = sync.Once{}
dir := t.TempDir()
logFile := filepath.Join(dir, "test.log")
require.NoError(t, ConfigureLogging(&conf.LoggingConfig{
File: logFile,
Level: "info",
Fields: map[string]interface{}{
"env": "test",
"region": "us-east-1",
},
SQL: LOG_SQL_ALL,
}))
// The configure path opens the log file before writing the "Set output
// file to ..." entry; the file must exist after the call returns.
_, err := os.Stat(logFile)
require.NoError(t, err)
}
func TestNewCustomFormatterFormatsTimeAsUTC(t *testing.T) {
f := NewCustomFormatter()
require.NotNil(t, f)
entry := logrus.NewEntry(logrus.New())
entry.Message = "hello"
out, err := f.Format(entry)
require.NoError(t, err)
require.Contains(t, string(out), "hello")
}
func TestSetPopLoggerExecutesAllSQLConfigs(t *testing.T) {
// setPopLogger registers a closure with pop.SetLogger; calling it for
// each documented SQL log mode covers the three branches that select
// shouldLogSQL and shouldLogSQLArgs.
for _, mode := range []string{LOG_SQL_NONE, LOG_SQL_STATEMENT, LOG_SQL_ALL, ""} {
setPopLogger(mode)
}
}