Documentation
¶
Index ¶
Constants ¶
const ( // ContainerID defines the id to be used as the container registration id // of a logging middleware instance factory function. ContainerID = rest.ContainerID + ".mwlog" // ContainerLoggerID container registration id of the default logger // instance to used. ContainerLoggerID = log.ContainerID // ContainerConfigOkID defines the id to be used as the container // registration id of a standard log config for a 200(OK) status code. ContainerConfigOkID = ContainerID + ".config.ok" // ContainerConfigCreatedID defines the id to be used as the container // registration id of a standard log config for a 201(Created) status code. ContainerConfigCreatedID = ContainerID + ".config.created" // ContainerConfigNoContentID defines the id to be used as the container // registration id of a standard log config for a 204(NoContent) status // code. ContainerConfigNoContentID = ContainerID + ".config.no_content" )
const ( // Env defines the gapp-rest/mwlog/log package environment entry id // base string. Env = rest.Env + "_MIDDLEWARE_LOG" // EnvRequestChannel defines the name of the environment // variable to be checked for an overriding value for the channel id used // on the request logging signal call. EnvRequestChannel = Env + "_REQUEST_CHANNEL" // EnvRequestLevel defines the name of the environment // variable to be checked for an overriding value for the logging level // used on the request logging signal call. EnvRequestLevel = Env + "_REQUEST_LEVEL" // EnvRequestMessage defines the name of the environment // variable to be checked for an overriding value for the request event // logging message used on the logging signal call EnvRequestMessage = Env + "_REQUEST_MESSAGE" // EnvResponseChannel defines the name of the environment // variable to be checked for an overriding value for the channel id used // on the response logging signal call. EnvResponseChannel = Env + "_RESPONSE_CHANNEL" // EnvResponseLevel defines the name of the environment // variable to be checked for an overriding value for the logging level // used on the response logging signal call. EnvResponseLevel = Env + "_RESPONSE_LEVEL" // EnvResponseMessage defines the name of the environment // variable to be checked for an overriding value for the response event // logging message used on the logging signal call EnvResponseMessage = Env + "_RESPONSE_MESSAGE" )
Variables ¶
var ( // RequestChannel defines the channel id to be used when the log // middleware sends the request logging signal to the logger instance. RequestChannel = "transport" // RequestLevel defines the logging level to be used when the log // middleware sends the request logging signal to the logger instance. RequestLevel = log.DEBUG // RequestMessage defines the request event logging message to // be used when the log middleware sends the logging signal to the logger // instance. RequestMessage = "Request" // ResponseChannel defines the channel id to be used when the log // middleware sends the response logging signal to the logger instance. ResponseChannel = "transport" // ResponseLevel defines the logging level to be used when the log // middleware sends the response logging signal to the logger instance. ResponseLevel = log.INFO // ResponseMessage defines the response event logging message // to be used when the log middleware sends the logging signal to the // logger instance. ResponseMessage = "Response" )
Functions ¶
func NewMiddleware ¶
func NewMiddleware(config Config, next gin.HandlerFunc) (gin.HandlerFunc, error)
NewMiddleware will instantiate a new middleware that will emit logging signals on a request event and on a response event.
func NewProvider ¶
NewProvider will create a new log middleware provider instance
Types ¶
type Config ¶
type Config struct {
Logger log.Logger
RequestReader RequestReader
RequestChannel string
RequestLevel log.Level
RequestMessage string
ResponseReader ResponseReader
ResponseChannel string
ResponseLevel log.Level
ResponseMessage string
}
Config defines the storing structure of the parameters used to configure the logging middleware.
type RequestReader ¶
RequestReader defines the interface of a request reader used in the log middleware.
func NewRequestReader ¶
func NewRequestReader() RequestReader
NewRequestReader will instantiate a new basic response context reader.
func NewRequestReaderJSON ¶
func NewRequestReaderJSON(reader RequestReader, model interface{}) (RequestReader, error)
NewRequestReaderJSON 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 NewRequestReaderXML ¶
func NewRequestReaderXML(reader RequestReader, model interface{}) (RequestReader, error)
NewRequestReaderXML will instantiate a new request event context reader XML decorator used to parse the request body as a XML and add the parsed content into the logging data.
type ResponseReader ¶
type ResponseReader interface {
Get(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 NewResponseReader ¶
func NewResponseReader(statusCode int) ResponseReader
NewResponseReader will instantiate a new basic response context reader.
func NewResponseReaderJSON ¶
func NewResponseReaderJSON(reader ResponseReader, model interface{}) (ResponseReader, error)
NewResponseReaderJSON 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 NewResponseReaderXML ¶
func NewResponseReaderXML(reader ResponseReader, model interface{}) (ResponseReader, error)
NewResponseReaderXML will instantiate a new response event context reader XML decorator used to parse the response body as a XML and add the parsed content into the logging data.
type ResponseWriter ¶
type ResponseWriter interface {
gin.ResponseWriter
Body() []byte
}
ResponseWriter defines the interface of a response writer used in the log middleware.
func NewResponseWriter ¶
func NewResponseWriter(writer gin.ResponseWriter) (ResponseWriter, error)
NewResponseWriter instantiate a new response writer proxy.