Categorygithub.com/execaus/exloggo
modulepackage
1.4.2
Repository: https://github.com/execaus/exloggo.git
Documentation: pkg.go.dev

# README

ExLogGo


Logger to integrate with the Gin library and support a chain of log messages.

Installation


To install ExLogGo package, you need to install Go and set your Go workspace first.

  1. You first need Go installed (version 1.19+ is required), then you can use the below Go command to install
go get -u github.com/execaus/exloggo
  1. Import it in your code:
import "github.com/execaus/exloggo"

Quick start


package main

import (
  "net/http"
  
  "github.com/gin-gonic/gin"
  "github.com/execaus/exloggo"
)

func main() {
  r := gin.Default()
  err := exloggo.SetParameters(exloggo.Parameters{
    Mode: exloggo.DevelopmentMode, // default development mode
    ServerVersion: "development",
    Directory: "/logs", // default "/logs"
  })
  if err != nil {
	  println(err.Error())
	  return
  }
  exloggo.Inject(r)
  r.GET("/ping", func(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
      "message": "pong",
    })
  })
  r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

Methods


Log output methods have variants with static message and formatted (with the prefix "f").

Base methodDescriptionPost effect
InfoGenerates an information log entrynone
WarningGenerates an warning log entrynone
ErrorGenerates an error log entrynone
FatalGenerates an fatal log entryexit program
RequestResultGenerates an Gin request lognone

Request Headers


The API supports the HTTP request headers listed below.

ЗаголовокТип значенияОписание
Client-Request-IDUUIDMandatory. A unique call identifier that is useful for logs and network tracing for troubleshooting purposes. The value must be set anew for each call.

Answer headers


The REST API supports the HTTP response headers listed below.

HeaderValue typeDescription
TimestamptimestampMandatory. A timestamp indicating when the request reached the API.
Client-Request-IDUUIDMandatory. A unique call identifier that is useful for logs and network tracing for troubleshooting purposes. The value must be set anew for each call. All operations must include this header.
Request-IDUUIDMandatory. A unique call identifier that is useful for logs and network tracing for troubleshooting purposes. The value must be set anew for each call. All operations must include this header.

Error resource type


An error response is a separate JSON object containing all the information about the error. You can use the data it returns instead of or together with the HTTP status code. Below is an example of the full JSON error text.

The table below describes the scheme of the error response.

FieldTypeDescription
codestringAlways returns. Indicates the type of error that occurred. Does not accept null.
messagestringAlways returns. Contains a detailed description of the error and additional information for debugging. Does not take null, cannot be empty. Maximum length: 1024 characters.

Code property


The code property contains one of the possible values listed below. Applications must be prepared to handle any of these errors.

CodeDescription
accessDeniedThe calling party does not have permission to perform the action.
generalExceptionAn unspecified error has occurred.
itemNotFoundResource not found.
invalidRequestThe request is in the wrong format or is incorrect.
resourceModifiedThe updated resource has changed since the last read.
unAuthenticatedThe calling object has not been authenticated.
sendEmailThe basic script was executed, but an error occurred while working with the SMTP server.
resourceDeletedAll actions with the resource are forbidden, because it was deleted.
notConfirmedThe data intended to confirm the action did not match the expected values.
timeoutExpiredThe time limit for performing the action has expired.
headerExceptionMandatory query headers are missing or incorrect.

Status codes


Status codeStatus messageDescription
200SuccessThe request was successful.
204No contentThe request was successful and the response does not contain a body.
400Request errorThe request could not be processed because it was in an invalid format or is invalid.
401Not authorizedThe necessary data for authentication is missing or is not valid for the resource.
403ProhibitedAccess to the requested resource is denied. Perhaps the user does not have enough permissions.
404Not foundThe requested resource does not exist.
405Метод не разрешенThe HTTP method in the request is not allowed for the resource.
410The method is not allowedThe requested, modified or deleted resource is removed from the server.
412A prerequisite is not metThe prerequisite specified in the request does not match the current state of the resource.
432Request HeadersAn error occurred while processing the query headers.
500Internal server errorAn internal server error occurred while processing the request.
501Not implementedThe requested function is not implemented.
506EmailThe SMTP server returned an error.
507Not enough storage spaceThe maximum storage quota has been reached.

Message property


The message property at the root contains an error message intended for the developer. Error messages are not localized and should not be shown directly to the user. When handling errors, code should not check message values, as they can change at any time, and they often contain dynamic information related to failed requests. The code should only handle error codes returned in the code properties.

Example output


{
  "level":"INFO",
  "message":"server started successfully",
  "point":"server/server.go:24",
  "request_id":"",
  "client_request_id":"",
  "timestamp":"2022-10-08T03:29:32Z",
  "server_version":"v1.0.0",
  "request":null,
  "extends":null
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author