Skip to content
Snippets Groups Projects
Select Git revision
  • 4445b89e9655585868f717d0e89770c6daf30dac
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • 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
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

global.go

Blame
  • global.go 1.66 KiB
    package logger
    
    import (
    	"fmt"
    	"os"
    
    	"gitlab.com/uafrica/go-utils/errors"
    )
    
    var logger Logger
    
    func init() {
    	logger = Logger{
    		level:  LevelDebug,
    		writer: os.Stderr,
    		data:   map[string]interface{}{},
    	}
    	//	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.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).log(LevelError, 1, fmt.Sprintf(format, args...))
    }
    
    func Error(args ...interface{}) {
    	logger.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).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...))
    }