logger

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithRequest

func ContextWithRequest(ctx context.Context, req *Request) context.Context

ContextWithRequest returns a new context from a parent context with request added into it

func ContextWithRequestType

func ContextWithRequestType(ctx context.Context, reqType RequestType) context.Context

ContextWithRequestType returns a new context from a parent context with request type added into it

func Init

func Init() error

Init initializes loggers

func LogPartnerRequest

func LogPartnerRequest(log *Request)

LogPartnerRequest logs a partner request to local file

func LogRequest

func LogRequest(log *Request)

LogRequest logs a request to local file

func LogUltronEx

func LogUltronEx(msg *UltronExMsg)

LogUltronEx logs a msg to UltronEx local file

func MaskJSON added in v0.1.15

func MaskJSON(json, maskChar string, toMasks []MaskData) string

MaskJSON mask parts of the json key paths value from the input json with replacement

Example:

input = `
{
	"first": "first value",
	"second": {
		"first": "1st of second",
		"second": "second@wego.com",
		"third": {
			"first": "1st of second third",
			"second": "2nd of second third",
			"third": "3rd of second third",
		}
	}
}`
maskData := []logger.MaskData{
	{
		JSONKey:         []string{"first"},
		FistCharsToShow: 3,
		LastCharsToShow: 6,
		KeepSameLength: true,
	},
	{
		JSONKey:         []string{"second", "second"},
		FistCharsToShow: 2,
		LastCharsToShow: 3,
		CharsToIgnore:   []rune{'@'},
		KeepSameLength: true,
	},
	{
		JSONKey:         []string{"second", "third", "first"},
		FistCharsToShow: 3,
		LastCharsToShow: 1,
		KeepSameLength: true,
	},
}
MaskJSON(input, "!", maskData) will return
{
	"first": "fir!! value",
	"second": {
		"first": "1st of second",
		"second": "se!!!!@!!!!!com",
		"third": {
			"first": "1st!!!!!!!!!!!!!!!d",
			"second": "2nd of second third",
			"third": "3rd of second third",
		}
	}
}

func MaskXML added in v0.1.15

func MaskXML(xml, maskChar string, toMasks []MaskData) string

MaskXML masks parts of the inner text of tags from the input XML with replacement

func RedactJSON

func RedactJSON(json, replacement string, keys [][]string) string

RedactJSON replaces value of key paths from the input JSON with replacement or defaultReplacement when replacement is empty

Example:

input = `
{
	"first": "first value",
	"second": {
		"first": "1st of second",
		"second": "2nd of second",
		"third": {
			"first": "1st of second third",
			"second": "2nd of second third",
			"third": "3rd of second third",
		}
	}
}`
keys := [][]string{{"first"}, {"second", "second"}, {"second", "third", "first"}}
RedactJSON(input, "Wego", keys) will return
{
	"first": "Wego",
	"second": {
		"first": "1st of second",
		"second": "Wego",
		"third": {
			"first": "Wego",
			"second": "2nd of second third",
			"third": "3rd of second third",
		}
	}
}

func RedactXML

func RedactXML(xml, replacement string, tags []string) string

RedactXML replaces inner text of tags from the input XML with replacement or defaultReplacement when replacement is empty

func Sync

func Sync()

Sync syncs all loggers

Types

type Headers

type Headers map[string]string

Headers ...

func (Headers) MarshalLogArray

func (h Headers) MarshalLogArray(enc zapcore.ArrayEncoder) error

MarshalLogArray marshal Headers to zap log array Need to implement this to log it with zap.Array

type MaskData added in v0.1.15

type MaskData struct {
	FirstCharsToShow int
	LastCharsToShow  int
	RestrictionType  MaskRestrictionType
	CharsToIgnore    []rune
	XMLTag           string
	JSONKeys         []string
	KeepSameLength   bool
	// contains filtered or unexported fields
}

MaskData the data as well as the information on how to mask the data

type MaskRestrictionType added in v0.1.15

type MaskRestrictionType string

MaskRestrictionType the type of text to mask, will only mask if text is of the specified type

const (
	// MaskRestrictionTypeEmail will only mask email text
	MaskRestrictionTypeEmail MaskRestrictionType = "email"
)

type Request

type Request struct {
	Type            RequestType
	Basics          common.Basics
	Method          string
	URL             string
	RequestHeaders  Headers
	RequestBody     string
	IP              string
	StatusCode      int32
	ResponseHeaders Headers
	ResponseBody    string
	RequestedAt     time.Time
	Duration        time.Duration
	Error           error
}

Request contains general information of a request

func RequestFromContext

func RequestFromContext(ctx context.Context) (req *Request)

RequestFromContext gets the request from context

func (*Request) AddBasics added in v0.1.4

func (r *Request) AddBasics(basics map[string]interface{})

AddBasics add the basics value

func (*Request) GetBasic added in v0.1.4

func (r *Request) GetBasic(key string) interface{}

GetBasic set the basic value for key

func (*Request) SetBasic added in v0.1.4

func (r *Request) SetBasic(key string, val interface{})

SetBasic set the basic value for key

func (*Request) SetBasics added in v0.1.4

func (r *Request) SetBasics(basics map[string]interface{})

SetBasics set the basics value

type RequestType

type RequestType string

RequestType ...

func RequestTypeFromContext

func RequestTypeFromContext(ctx context.Context) (reqType RequestType)

RequestTypeFromContext gets the request type from context

type UltronExMsg

type UltronExMsg struct {
	Channel string
	Text    string
	Payload string
	Title   string
}

UltronExMsg ...

func (UltronExMsg) MarshalLogObject

func (m UltronExMsg) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject marshal UltronExMsg to zap log object The struct need to implement this, so we can log it with zap.Object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL