time format

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/5/head
jolheiser 2021-02-16 23:57:38 -06:00
parent 262effd971
commit 45d3d34382
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
2 changed files with 1 additions and 37 deletions

View File

@ -3,7 +3,6 @@ package beaver
import (
"fmt"
"strings"
"time"
"go.jolheiser.com/beaver/color"
)
@ -105,38 +104,3 @@ func ParseLevel(level string) Level {
}
return INFO
}
func timePrefix(t time.Time) string {
var buf = &[]byte{}
year, month, day := t.Date()
itoa(buf, int(month), 2)
*buf = append(*buf, '/')
itoa(buf, day, 2)
*buf = append(*buf, '/')
itoa(buf, year, 4)
*buf = append(*buf, ' ')
hour, min, sec := t.Clock()
itoa(buf, hour, 2)
*buf = append(*buf, ':')
itoa(buf, min, 2)
*buf = append(*buf, ':')
itoa(buf, sec, 2)
return string(*buf)
}
func itoa(buf *[]byte, i int, wid int) {
var b [20]byte
bp := len(b) - 1
for i >= 10 || wid > 1 {
wid--
q := i / 10
b[bp] = byte('0' + i - q*10)
bp--
i = q
}
// i < 10
b[bp] = byte('0' + i)
*buf = append(*buf, b[bp:]...)
}

View File

@ -42,7 +42,7 @@ func (l *Logger) write(level Level, text string) {
if l.Level <= level {
var message string
if l.Format.TimePrefix {
message += color.Time.Format(timePrefix(time.Now())) + " "
message += color.Time.Format(time.Now().Format("01/02/2006 15:04:05")) + " "
}
if l.Format.StackPrefix {
_, file, line, _ := runtime.Caller(l.skip)