mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-29 01:44:39 +02:00
7c6bd86b28
do not write fields et al, let it just roll, otherwise its too noisy, and we might expose things we are not supposed to. closes #3741 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
37 lines
683 B
Go
37 lines
683 B
Go
package logext
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/caarlos0/log"
|
|
)
|
|
|
|
// NewWriter creates a new log writer.
|
|
func NewWriter() io.Writer {
|
|
return NewConditionalWriter(false)
|
|
}
|
|
|
|
// NewConditionalWriter creates a new log writer that only writes when the given condition is met or debug is enabled.
|
|
func NewConditionalWriter(condition bool) io.Writer {
|
|
if condition || isDebug() {
|
|
logger, ok := log.Log.(*log.Logger)
|
|
if !ok {
|
|
return os.Stderr
|
|
}
|
|
return logger.Writer
|
|
}
|
|
return io.Discard
|
|
}
|
|
|
|
func isDebug() bool {
|
|
return logLevel() == log.DebugLevel
|
|
}
|
|
|
|
func logLevel() log.Level {
|
|
if logger, ok := log.Log.(*log.Logger); ok {
|
|
return logger.Level
|
|
}
|
|
return log.InfoLevel
|
|
}
|