Skip to content
Snippets Groups Projects
Select Git revision
  • 90ec162f4b59c68672a981f51916632a94e95b1c
  • main default protected
  • v1.302.0
  • v1.301.0
  • v1.300.0
  • v1.299.0
  • v1.298.0
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
22 results

global.go

Blame
  • global.go 1.60 KiB
    package logger
    
    import (
    	"fmt"
    	"os"
    
    	"github.com/fatih/color"
    
    	"gitlab.com/uafrica/go-utils/errors"
    )
    
    var logger Logger
    
    func init() {
    	logger = Logger{
    		level:  LevelDebug,
    		writer: os.Stderr,
    		data:   map[string]interface{}{},
    		fg:     color.FgWhite,
    		bg:     color.BgBlack,
    	}
    	//	InitLogs(nil, nil)
    }
    
    func New() Logger {
    	return logger.WithFields(nil)
    }
    
    //shortcut functions to use current logger
    //this should only be used outside of a request context
    //or anywhere if you have a single threaded process
    func Fatalf(format string, args ...interface{}) {
    	logger.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).log(LevelFatal, 1, fmt.Sprintf(format, args...))
    	os.Exit(1)
    }
    
    func Fatal(args ...interface{}) {
    	logger.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).log(LevelFatal, 1, fmt.Sprint(args...))
    	os.Exit(1)
    }
    
    func Errorf(format string, args ...interface{}) {
    	logger.log(LevelError, 1, fmt.Sprintf(format, args...))
    }
    
    func Error(args ...interface{}) {
    	logger.log(LevelError, 1, fmt.Sprint(args...))
    }
    
    func Warnf(format string, args ...interface{}) {
    	logger.log(LevelWarn, 1, fmt.Sprintf(format, args...))
    }
    
    func Warn(args ...interface{}) {
    	logger.log(LevelWarn, 1, fmt.Sprint(args...))
    }
    
    func Infof(format string, args ...interface{}) {
    	logger.log(LevelInfo, 1, fmt.Sprintf(format, args...))
    }
    
    func Info(args ...interface{}) {
    	logger.log(LevelInfo, 1, fmt.Sprint(args...))
    }
    
    func Debugf(format string, args ...interface{}) {
    	logger.log(LevelDebug, 1, fmt.Sprintf(format, args...))
    }
    
    func Debug(args ...interface{}) {
    	logger.log(LevelDebug, 1, fmt.Sprint(args...))
    }