begin, end

master
Charles Iliya Krempeaux 2021-02-10 11:40:40 -08:00
parent e7446423ca
commit abffb60501
3 changed files with 18 additions and 0 deletions

View File

@ -2,12 +2,15 @@ package flog
import ( import (
"io" "io"
"time"
) )
type internalLogger struct { type internalLogger struct {
prefix string prefix string
style string style string
begin time.Time
writer io.Writer writer io.Writer
mutedAlert bool mutedAlert bool

View File

@ -2,6 +2,7 @@ package flog
import ( import (
"runtime" "runtime"
"time"
) )
func (receiver internalLogger) Begin(a ...interface{}) Logger { func (receiver internalLogger) Begin(a ...interface{}) Logger {
@ -16,6 +17,10 @@ func (receiver internalLogger) Begin(a ...interface{}) Logger {
} }
logger := receiver.Prefix(funcName) logger := receiver.Prefix(funcName)
switch casted := logger.(type) {
case *internalLogger:
casted.begin = time.Now()
}
a = append([]interface{}{"BEGIN"}, a...) a = append([]interface{}{"BEGIN"}, a...)

View File

@ -1,7 +1,17 @@
package flog package flog
import (
"fmt"
"time"
)
func (receiver internalLogger) End(a ...interface{}) { func (receiver internalLogger) End(a ...interface{}) {
diff := time.Now().Sub(receiver.begin)
msg := fmt.Sprintf(" δt=%s", diff)
a = append([]interface{}{"END"}, a...) a = append([]interface{}{"END"}, a...)
a = append(a, msg)
receiver.Debug(a...) receiver.Debug(a...)
} }