Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Copyright © 2024 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package popx
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/ory/pop/v6"
|
|
"github.com/ory/pop/v6/logging"
|
|
)
|
|
|
|
func formatter(lvl logging.Level, s string, args ...interface{}) string {
|
|
if pop.Debug == false {
|
|
return ""
|
|
}
|
|
|
|
if lvl == logging.SQL {
|
|
if len(args) > 0 {
|
|
xargs := make([]string, len(args))
|
|
for i, a := range args {
|
|
switch a.(type) {
|
|
case string:
|
|
xargs[i] = fmt.Sprintf("%q", a)
|
|
default:
|
|
xargs[i] = fmt.Sprintf("%v", a)
|
|
}
|
|
}
|
|
s = fmt.Sprintf("%s - %s | %s", lvl, s, xargs)
|
|
} else {
|
|
s = fmt.Sprintf("%s - %s", lvl, s)
|
|
}
|
|
} else {
|
|
s = fmt.Sprintf(s, args...)
|
|
s = fmt.Sprintf("%s - %s", lvl, s)
|
|
}
|
|
return s
|
|
}
|
|
|
|
func TestingLogger(t testing.TB) func(lvl logging.Level, s string, args ...interface{}) {
|
|
return func(lvl logging.Level, s string, args ...interface{}) {
|
|
if line := formatter(lvl, s, args...); len(line) > 0 {
|
|
t.Log(line)
|
|
}
|
|
}
|
|
}
|
|
|
|
func NullLogger() func(lvl logging.Level, s string, args ...interface{}) {
|
|
return func(lvl logging.Level, s string, args ...interface{}) {
|
|
// do nothing
|
|
}
|
|
}
|