Time format (#5)

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/beaver/pulls/5
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-committed-by: John Olheiser <john.olheiser@gmail.com>
main v1.1.1
John Olheiser 2021-02-17 13:58:17 +08:00
parent 262effd971
commit 0b1a1e4bd0
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)