logging.go (1085B)
1 package logging 2 3 import ( 4 "context" 5 "io" 6 "os" 7 ) 8 9 const ( 10 LVL_NONE = iota 11 LVL_ERROR 12 LVL_WARN 13 LVL_INFO 14 LVL_DEBUG 15 LVL_TRACE 16 ) 17 18 var ( 19 levelStr = map[int]string{ 20 LVL_ERROR: "E", 21 LVL_WARN: "W", 22 LVL_INFO: "I", 23 LVL_DEBUG: "D", 24 LVL_TRACE: "T", 25 } 26 ) 27 28 var ( 29 LogWriter = os.Stderr 30 ) 31 32 33 func AsString(level int) string { 34 return levelStr[level] 35 } 36 37 38 type Logger interface { 39 Writef(w io.Writer, level int, msg string, args ...any) 40 WriteCtxf(ctx context.Context, w io.Writer, level int, msg string, args ...any) 41 Printf(level int, msg string, args ...any) 42 PrintCtxf(ctx context.Context, level int, msg string, args ...any) 43 Tracef(msg string, args ...any) 44 TraceCtxf(ctx context.Context, msg string, args ...any) 45 Debugf(msg string, args ...any) 46 DebugCtxf(ctx context.Context, msg string, args ...any) 47 Infof(msg string, args ...any) 48 InfoCtxf(ctx context.Context, msg string, args ...any) 49 Warnf(msg string, args ...any) 50 WarnCtxf(ctx context.Context, msg string, args ...any) 51 Errorf(msg string, args ...any) 52 ErrorCtxf(ctx context.Context, msg string, args ...any) 53 } 54