logging

package
v0.0.0-...-0ff7356 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Deprecated: use options to configure logging

Index

Constants

This section is empty.

Variables

View Source
var ZerologDefaultInterfaceMarshalFunc = zerolog.InterfaceMarshalFunc

ZerologDefaultInterfaceMarshalFunc is the default marshal function used by zerolog

View Source
var ZerologInterfacePLCMessageFormat = PLCMessageAsJSON

ZerologInterfacePLCMessageFormat defines the format of the PLCMessage that is logged by the zerolog interface marshal function

View Source
var ZerologMessageInterfaceMarshalFunc = func(v any) ([]byte, error) {
	if plcMessage, ok := v.(utils.Serializable); ok {
		switch ZerologInterfacePLCMessageFormat {
		case PLCMessageAsJSON:
			jsonWriteBuffer := utils.NewJsonWriteBuffer(
				utils.WithJsonWriteBufferDefaultIdent(false),
			)
			if err := plcMessage.SerializeWithWriteBuffer(context.Background(), jsonWriteBuffer); err != nil {
				return nil, errors.Wrap(err, "error serializing PLCMessage")
			}
			jsonString, err := jsonWriteBuffer.GetJsonString()
			if err != nil {
				return nil, errors.Wrapf(err, "error getting JSON string from PLCMessage")
			}
			b := []byte(jsonString)
			if len(b) > 0 {

				return b[:len(b)-1], nil
			}
			return b, nil
		case PLCMessageAsString:
			boxWriteBuffer := utils.NewWriteBufferBoxBased(
				utils.WithWriteBufferBoxBasedMergeSingleBoxes(),
				utils.WithWriteBufferBoxBasedOmitEmptyBoxes(),
				utils.WithWriteBufferBoxBasedDesiredWidth(200),
				utils.WithWriteBufferBoxBasedPrintPosLengthFooter(),
			)
			if err := plcMessage.SerializeWithWriteBuffer(context.Background(), boxWriteBuffer); err != nil {
				return nil, errors.Wrap(err, "error serializing PLCMessage")
			}
			boxString := boxWriteBuffer.GetBox().String()
			return json.Marshal(boxString)
		case PLCMessageAsXML:
			xmlWriteBuffer := utils.NewXmlWriteBuffer(
				utils.WithXmlWriteBufferDefaultIdent(false),
			)
			if err := plcMessage.SerializeWithWriteBuffer(context.Background(), xmlWriteBuffer); err != nil {
				return nil, errors.Wrap(err, "error serializing PLCMessage")
			}
			xmlString := xmlWriteBuffer.GetXmlString()
			return json.Marshal(xmlString)
		case PLCMessageAsByte:
			byteWriteBuffer := utils.NewWriteBufferByteBased()
			if err := plcMessage.SerializeWithWriteBuffer(context.Background(), byteWriteBuffer); err != nil {
				return nil, errors.Wrap(err, "error serializing PLCMessage")
			}
			bytes := byteWriteBuffer.GetBytes()
			return json.Marshal(bytes)
		}
	}
	return ZerologDefaultInterfaceMarshalFunc(v)
}

ZerologMessageInterfaceMarshalFunc is the marshal function used by zerolog to serialize PLCMessages. To use it just do a zerolog.InterfaceMarshalFunc = ZerologMessageInterfaceMarshalFunc in a init function.

Functions

This section is empty.

Types

type PLCMessageFormat

type PLCMessageFormat uint8

PLCMessageFormat defines the format of the PLCMessage that is logged

const (
	// PLCMessageAsJSON defines the format of the PLCMessage as JSON
	PLCMessageAsJSON PLCMessageFormat = iota
	// PLCMessageAsString defines the format of the PLCMessage as a string
	PLCMessageAsString
	// PLCMessageAsXML defines the format of the PLCMessage as XML
	PLCMessageAsXML
	// PLCMessageAsByte defines the format of the PLCMessage as a byte array
	PLCMessageAsByte
)

Jump to

Keyboard shortcuts

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