go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

logging.go (2546B)


      1 package logging
      2 
      3 import (
      4 	"context"
      5 	"io"
      6 )
      7 
      8 const (
      9 	// No logging
     10 	LVL_NONE = iota
     11 	// Error log level - unexpected states that need immediate developer attention.
     12 	LVL_ERROR
     13 	// Warning log level - unexpected states that may need developer attention.
     14 	LVL_WARN
     15 	// Info log level - expected states that are of general interest to the end-user.
     16 	LVL_INFO
     17 	// Debug log level - expected states that are of general interest to the developer.
     18 	LVL_DEBUG
     19 	// Trace log level - everything else.
     20 	LVL_TRACE
     21 )
     22 
     23 var (
     24 	levelStr = map[int]string{
     25 		LVL_ERROR: "E",	
     26 		LVL_WARN: "W",	
     27 		LVL_INFO: "I",	
     28 		LVL_DEBUG: "D",	
     29 		LVL_TRACE: "T",	
     30 	}
     31 )
     32 
     33 // AsString returns the string representation used in logging output for the given log level.
     34 func AsString(level int) string {
     35 	return levelStr[level]	
     36 }
     37 
     38 type Logger interface {
     39 	// Writef logs a line to the given writer with the given loglevel.
     40 	Writef(w io.Writer, level int, msg string, args ...any)
     41 	// WriteCtxf logs a line with context to the given writer with the given loglevel.
     42 	WriteCtxf(ctx context.Context, w io.Writer, level int, msg string, args ...any)
     43 	// Printf logs a line to the default writer with the given loglevel.
     44 	Printf(level int, msg string, args ...any)
     45 	// Printf logs a line with context to the default writer with the given loglevel.
     46 	PrintCtxf(ctx context.Context, level int, msg string, args ...any)
     47 	// Tracef logs a line to the default writer the TRACE loglevel.
     48 	Tracef(msg string, args ...any)
     49 	// TraceCtxf logs a line with context to the default writer the TRACE loglevel.
     50 	TraceCtxf(ctx context.Context, msg string, args ...any)
     51 	// Debugf logs a line to the default writer the DEBUG loglevel.
     52 	Debugf(msg string, args ...any)
     53 	// DebugCtxf logs a line with context to the default writer the DEBUG loglevel.
     54 	DebugCtxf(ctx context.Context, msg string, args ...any)
     55 	// Infof logs a line to the default writer the INFO loglevel.
     56 	Infof(msg string, args ...any)
     57 	// InfoCtxf logs a line with context to the default writer the INFO loglevel.
     58 	InfoCtxf(ctx context.Context, msg string, args ...any)
     59 	// Warnf logs a line to the default writer the WARN loglevel.
     60 	Warnf(msg string, args ...any)
     61 	// WarnCtxf logs a line with context to the default writer the WARN loglevel.
     62 	WarnCtxf(ctx context.Context, msg string, args ...any)
     63 	// Errorf logs a line to the default writer the ERROR loglevel.
     64 	Errorf(msg string, args ...any)
     65 	// ErrorCtxf logs a line with context to the default writer the ERROR loglevel.
     66 	ErrorCtxf(ctx context.Context, msg string, args ...any)
     67 }
     68