Commit 6192f238 authored by Carsten Orthbandt's avatar Carsten Orthbandt

logfunk.P, allow ommiting the LogSink in MakeF()

parent 0e829bb1
......@@ -328,7 +328,19 @@ func extractFormatType(format string) int {
}
// MakeF creates a new log function on a LogSink (which can be another LogFunc or nil) with optional default values
func MakeF(ls LogSink, defaults ...interface{}) F {
func MakeF(defaults ...interface{}) F {
var ls LogSink
// we do this dance to allow nil-value interfaces of logfunk.F to be passed
if len(defaults) > 0 {
if lf, ok := defaults[0].(F); ok {
if lf != nil {
ls = lf
}
} else if lsi, ok := defaults[0].(LogSink); ok {
ls = lsi
defaults = defaults[1:]
}
}
if ls == nil {
ls = StdSink()
}
......@@ -465,12 +477,17 @@ func (le *LogEntry) AddCallerAttribute() {
var pGlobal F
var pGlobalInit sync.Once
// PPrep sets defaults for the logfunk.P convenience function
func PPrep(args ...interface{}) {
pGlobalInit.Do(func() {
pGlobal = MakeF(StdSink(), args...)
var lsi []interface{}
lsi = append(lsi, StdSink())
lsi = append(lsi, args...)
pGlobal = MakeF(lsi...)
})
}
// P is a convenience logging function using the StdSink. It is initialized on demand.
func P(args ...interface{}) {
pGlobalInit.Do(func() {
pGlobal = MakeF(StdSink())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment