Skip to content
Snippets Groups Projects
Select Git revision
  • 7aacf2100f22701c403ee76df551d6e4699a8f60
  • 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

encryption.go

Blame
  • logger.go 6.15 KiB
    package logger
    
    import (
    	"bytes"
    	"encoding/json"
    	"fmt"
    	"io"
    	"strings"
    	"time"
    
    	"github.com/fatih/color"
    	"gitlab.com/uafrica/go-utils/errors"
    )
    
    type ILogger interface {
    	Fatalf(format string, args ...interface{})
    	Fatal(args ...interface{})
    	Errorf(format string, args ...interface{})
    	Error(args ...interface{})
    	Warnf(format string, args ...interface{})
    	Warn(args ...interface{})
    	Infof(format string, args ...interface{})
    	Info(args ...interface{})
    	Debugf(format string, args ...interface{})
    	Debug(args ...interface{})
    }
    
    type Logger struct {
    	//apiRequest       *events.APIGatewayProxyRequest
    	//currentRequestID *string
    	level  Level
    	writer io.Writer
    	data   map[string]interface{}
    }
    
    func (l Logger) WithFields(data map[string]interface{}) Logger {
    	newLogger := Logger{
    		level:  l.level,
    		writer: l.writer,
    		data:   map[string]interface{}{},
    	}
    	for n, v := range l.data {
    		newLogger.data[n] = v
    	}
    	for n, v := range data {
    		newLogger.data[n] = v
    	}
    	return newLogger
    }
    
    func (l Logger) Fatalf(format string, args ...interface{}) {
    	l.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).log(LevelFatal, 1, fmt.Sprintf(format, args...))
    }
    
    func (l Logger) Fatal(args ...interface{}) {
    	l.WithFields(map[string]interface{}{"call_stack": errors.Stack(3)}).log(LevelFatal, 1, fmt.Sprint(args...))
    }
    
    func (l Logger) Errorf(format string, args ...interface{}) {
    	l.log(LevelError, 1, fmt.Sprintf(format, args...))
    }
    
    func (l Logger) Error(args ...interface{}) {
    	l.log(LevelError, 1, fmt.Sprint(args...))
    }
    
    func (l Logger) Warnf(format string, args ...interface{}) {
    	l.log(LevelWarn, 1, fmt.Sprintf(format, args...))
    }