Time format #5

Merged
jolheiser merged 1 commits from refs/pull/5/head into main 2021-02-17 05:58:17 +00:00
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)