srlog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerID defines the id to be used as the container
	// registration id of a logging middleware instance factory function.
	ContainerID = slaterest.ContainerID + ".log"

	// ContainerOkID defines the id to be used as the
	// container registration id of a standard log middleware generator
	// for a 200(OK) status code.
	ContainerOkID = ContainerID + ".ok"

	// ContainerCreatedID defines the id to be used as
	// the container registration id of a standard log middleware generator
	// for a 201(Created) status code.
	ContainerCreatedID = ContainerID + ".created"

	// ContainerNoContentID defines the id to be used as
	// the container registration id of a standard log middleware generator
	// for a 204(NoContent) status code.
	ContainerNoContentID = ContainerID + ".no_content"
)
View Source
const (
	// EnvID defines the slate.slaterest.log package base environment variable name.
	EnvID = slaterest.EnvID + "_LOG"
)

Variables

View Source
var (
	// RequestChannel defines the channel id to be used when
	// the log middleware sends the request logging signal to the logger
	// instance.
	RequestChannel = senv.String(EnvID+"_REQUEST_CHANNEL", "transport")

	// RequestLevel defines the logging level to be used when
	// the log middleware sends the request logging signal to the logger
	// instance.
	RequestLevel = envToLogLevel(EnvID+"_REQUEST_LEVEL", slog.DEBUG)

	// RequestMessage defines the request event logging message to
	// be used when the log middleware sends the logging signal to the logger
	// instance.
	RequestMessage = senv.String(EnvID+"_REQUEST_MESSAGE", "Request")

	// ResponseChannel defines the channel id to be used when the
	// log middleware sends the response logging signal to the logger instance.
	ResponseChannel = senv.String(EnvID+"_RESPONSE_CHANNEL", "transport")

	// ResponseLevel defines the logging level to be used when the
	// log middleware sends the response logging signal to the logger instance.
	ResponseLevel = envToLogLevel(EnvID+"_RESPONSE_LEVEL", slog.INFO)

	// ResponseMessage defines the response event logging message
	// to be used when the log middleware sends the logging signal to the
	// logger instance.
	ResponseMessage = senv.String(EnvID+"_RESPONSE_MESSAGE", "Response")

	// DecorateJSON flag that defines the decoration of the log entries
	// for JSON body content.
	DecorateJSON = senv.Bool(EnvID+"_DECORATE_JSON", true)

	// DecorateXML flag that defines the decoration of the log entries
	// for XML body content.
	DecorateXML = senv.Bool(EnvID+"_DECORATE_XML", false)
)

Functions

func GetMiddlewareCreated

func GetMiddlewareCreated(c slate.ServiceContainer) (slaterest.Middleware, error)

GetMiddlewareCreated will try to retrieve the registered logging middleware for created responses instance from the application service container.

func GetMiddlewareNoContent

func GetMiddlewareNoContent(c slate.ServiceContainer) (slaterest.Middleware, error)

GetMiddlewareNoContent will try to retrieve the registered logging middleware for no-content responses instance from the application service container.

func GetMiddlewareOk

func GetMiddlewareOk(c slate.ServiceContainer) (slaterest.Middleware, error)

GetMiddlewareOk will try to retrieve the registered logging middleware for ok responses instance from the application service container.

func NewMiddleware

func NewMiddleware(
	logger *slog.Logger,
	requestReader RequestReader,
	responseReader ResponseReader,
) (slaterest.Middleware, error)

NewMiddleware will instantiate a new middleware that will emit logging signals on a request event and on a response event.

func RequestReaderDefault

func RequestReaderDefault(ctx *gin.Context) (map[string]interface{}, error)

RequestReaderDefault is the default function used to parse the request context information.

Types

type Provider

type Provider struct{}

Provider defines the gapp-rest-log module service provider to be used on the application initialization to register the logging middleware service.

func (Provider) Boot

Boot will start the migration package If the auto migration is defined as true, ether by global variable or by environment variable, the migrator will automatically try to migrate to the last registered migration

func (Provider) Register

func (p Provider) Register(c slate.ServiceContainer) error

Register will register the log middleware package instances in the application container

type RequestReader

type RequestReader func(ctx *gin.Context) (map[string]interface{}, error)

RequestReader defines the function used by the middleware that compose the logging request context object.

func NewRequestReaderDecoratorJSON

func NewRequestReaderDecoratorJSON(reader RequestReader, model interface{}) (RequestReader, error)

NewRequestReaderDecoratorJSON will instantiate a new request event context reader JSON decorator used to parse the request body as a JSON and add the parsed content into the logging data.

func NewRequestReaderDecoratorXML

func NewRequestReaderDecoratorXML(reader RequestReader, model interface{}) (RequestReader, error)

NewRequestReaderDecoratorXML will instantiate a new request event context reader XML decorator used to parse the request body as an XML and add the parsed content into the logging data.

type RequestReaderDecorator

type RequestReaderDecorator func(reader RequestReader, model interface{}) (RequestReader, error)

RequestReaderDecorator defines a function used to decorate a request reader output.

type ResponseReader

type ResponseReader func(ctx *gin.Context, writer responseWriter) (map[string]interface{}, error)

ResponseReader defines the interface methods of a response context reader used to compose the data to be sent to the logger on a response event.

func NewResponseReaderDecoratorJSON

func NewResponseReaderDecoratorJSON(reader ResponseReader, model interface{}) (ResponseReader, error)

NewResponseReaderDecoratorJSON will instantiate a new response event context reader JSON decorator used to parse the response body as a JSON and add the parsed content into the logging data.

func NewResponseReaderDecoratorXML

func NewResponseReaderDecoratorXML(reader ResponseReader, model interface{}) (ResponseReader, error)

NewResponseReaderDecoratorXML will instantiate a new response event context reader XML decorator used to parse the response body as an XML and add the parsed content into the logging data.

func NewResponseReaderDefault

func NewResponseReaderDefault(statusCode int) ResponseReader

NewResponseReaderDefault generates a new default response reader with the defined expected status code.

type ResponseReaderDecorator

type ResponseReaderDecorator func(reader ResponseReader, model interface{}) (ResponseReader, error)

ResponseReaderDecorator defines a function used to decorate a response reader output.

Jump to

Keyboard shortcuts

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