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.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...))
}