Documentation ¶
Overview ¶
Package testlog creates a *log.Logger backed by *testing.T to ease logging in tests. This allows logs from components being tested to only be printed if the test fails (or the verbose flag is specified).
Index ¶
- func HCLogger(t LogPrinter) hclog.InterceptLogger
- func HCLoggerNode(t LogPrinter, node int32) (hclog.InterceptLogger, io.Writer)
- func HCLoggerTestLevel() hclog.Level
- func Logger(t LogPrinter) *log.Logger
- func New(t LogPrinter, prefix string, flag int) *log.Logger
- func NewPrefixWriter(t LogPrinter, prefix string) io.Writer
- func NewWriter(t LogPrinter) io.Writer
- func WithPrefix(t LogPrinter, prefix string) *log.Logger
- type LogPrinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HCLogger ¶ added in v0.9.0
func HCLogger(t LogPrinter) hclog.InterceptLogger
HCLogger returns a new test hc-logger.
Default log level is TRACE. Set NOMAD_TEST_LOG_LEVEL for custom log level.
func HCLoggerNode ¶ added in v1.1.13
func HCLoggerNode(t LogPrinter, node int32) (hclog.InterceptLogger, io.Writer)
HCLoggerNode returns a new hc-logger, but with a prefix indicating the node number on each log line. Useful for TestServer in tests with more than one server.
Default log level is TRACE. Set NOMAD_TEST_LOG_LEVEL for custom log level.
func HCLoggerTestLevel ¶ added in v1.1.13
HCLoggerTestLevel returns the level in which hc log should emit logs.
Default log level is TRACE. Set NOMAD_TEST_LOG_LEVEL for custom log level.
func Logger ¶
func Logger(t LogPrinter) *log.Logger
Logger returns a new test logger with the Lmicroseconds flag set and no prefix.
Note: only use this where HCLogger cannot be used (i.e. RPC yamux configuration).
func New ¶
func New(t LogPrinter, prefix string, flag int) *log.Logger
New returns a new test logger. See https://golang.org/pkg/log/#New
func NewPrefixWriter ¶ added in v0.9.0
func NewPrefixWriter(t LogPrinter, prefix string) io.Writer
NewPrefixWriter creates a new io.Writer backed by a Logger with a custom prefix per Write.
func NewWriter ¶
func NewWriter(t LogPrinter) io.Writer
NewWriter creates a new io.Writer backed by a Logger.
func WithPrefix ¶
func WithPrefix(t LogPrinter, prefix string) *log.Logger
WithPrefix returns a new test logger with the Lmicroseconds flag set.
Types ¶
type LogPrinter ¶
type LogPrinter interface {
Logf(format string, args ...interface{})
}
LogPrinter is the methods of testing.T (or testing.B) needed by the test logger.