code.dwrz.net

Go monorepo.
Log | Files | Refs

log.go (445B)


      1 package log
      2 
      3 import (
      4 	"log"
      5 	"os"
      6 	"runtime/debug"
      7 )
      8 
      9 const flags = log.Ldate | log.Lmicroseconds | log.Lshortfile | log.LUTC
     10 
     11 type Logger struct {
     12 	Error *log.Logger
     13 	Info  *log.Logger
     14 }
     15 
     16 func New(f *os.File) *Logger {
     17 	return &Logger{
     18 		Error: log.New(f, "ERROR ", flags),
     19 		Info:  log.New(f, "INFO ", flags),
     20 	}
     21 }
     22 
     23 func (l *Logger) Recover() {
     24 	if msg := recover(); msg != nil {
     25 		l.Error.Printf("panic: %v:\n%s\n", msg, debug.Stack())
     26 	}
     27 }