code.dwrz.net

Go monorepo.
Log | Files | Refs

commit 5053ed144bc2839d7ef29f8689fcba6a19668a71
parent 60e4d329c8deae3336cd72bc6b02027be8dbb4c0
Author: dwrz <dwrz@dwrz.net>
Date:   Fri, 14 Oct 2022 00:33:40 +0000

Add log pkg

Diffstat:
Apkg/log/log.go | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/pkg/log/log.go b/pkg/log/log.go @@ -0,0 +1,27 @@ +package log + +import ( + "log" + "os" + "runtime/debug" +) + +const flags = log.Ldate | log.Lmicroseconds | log.Lshortfile | log.LUTC + +type Logger struct { + Error *log.Logger + Info *log.Logger +} + +func New() *Logger { + return &Logger{ + Error: log.New(os.Stderr, "ERROR ", flags), + Info: log.New(os.Stderr, "INFO ", flags), + } +} + +func (l *Logger) Recover() { + if msg := recover(); msg != nil { + l.Error.Printf("panic: %v:\n%s\n", msg, debug.Stack()) + } +}