3

I have made RESTFUL API using GO and existing Module like ECHO, GORM, WIRE, LOGRUS, VIPER.

But i dont know best practice how to create Beautiful Logger for every activity when someone Hit or Consume my endpoint URL in all HTTP Method Request (GET/POST/PUT/DEL/UPDATE). Can someone give me a example or some reference i need to read and try? or sharing your experience about logger in system using GO

Beautiful Logger i mean is addition information about who accessing my endpoint like current environtment, UTC Datetime, some authorization name, some authorization role, endpoint, http method, request body IF Exists, http status code, http response, ip address, etc.

Logger i want:

[2022-12-17 00:00:00 UTC] env=development auth_email=patrick@example.example auth_role=admin endpoint={BASE_URL}/users/1 http_method=GET http_request_body={JSON from STRUCT} http_status=200 http_response={JSON from STRUCT} device_ip_address=192.168.1.1 device_os=windows

[2022-12-17 01:00:02 UTC] env=development auth_email=tommy@example.example auth_role=basic endpoint={BASE_URL}/users http_method=GET http_request_body={JSON from STRUCT} http_status=200 http_response={JSON from STRUCT} device_ip_address=192.168.1.1 device_os=ubuntu

ramadoiranedar
  • 137
  • 2
  • 7

0 Answers0