Skip to content

Conversation

@yokeTH
Copy link
Owner

@yokeTH yokeTH commented Jun 16, 2025

TODO

  • Write Docs

Output

Trace level and Json is false

7:07AM INF incoming request req={"body":"{\n  \"author\": \"pariatur voluptate ullamco est\",\n  \"title\": \"esse\"\n}","method":"POST","path":"/books","query":{}} request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC enter bookHandler.CreateBook request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC enter bookUseCase.Create request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM INF usecase: creating book book={"Author":"pariatur voluptate ullamco est","CreatedAt":"0001-01-01T00:00:00Z","DeletedAt":null,"ID":0,"Title":"esse","UpdatedAt":"0001-01-01T00:00:00Z"} request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC enter bookRepository.Create request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM INF creating book book={"Author":"pariatur voluptate ullamco est","CreatedAt":"0001-01-01T00:00:00Z","DeletedAt":null,"ID":0,"Title":"esse","UpdatedAt":"0001-01-01T00:00:00Z"} request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM INF book created successfully book={"Author":"pariatur voluptate ullamco est","CreatedAt":"2025-06-16T14:07:19.883787+07:00","DeletedAt":null,"ID":7,"Title":"esse","UpdatedAt":"2025-06-16T14:07:19.883787+07:00"} request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC exit bookRepository.Create request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM INF usecase: book created successfully book={"Author":"pariatur voluptate ullamco est","CreatedAt":"2025-06-16T14:07:19.883787+07:00","DeletedAt":null,"ID":7,"Title":"esse","UpdatedAt":"2025-06-16T14:07:19.883787+07:00"} request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC exit bookUseCase.Create request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM TRC exit bookHandler.CreateBook request_id=de0ac196-9e0e-4d01-885c-94917c97a150
7:07AM INF processed request request_id=de0ac196-9e0e-4d01-885c-94917c97a150 res={"body":"{\"data\":{\"id\":7,\"title\":\"esse\",\"author\":\"pariatur voluptate ullamco est\"}}","method":"POST","path":"/books","process_ms":23,"status":201}

or
Info level and Json is true

{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","req":{"body":"{\n  \"author\": \"pariatur voluptate ullamco est\",\n  \"title\": \"esse\"\n}","method":"POST","path":"/books","query":{}},"timestamp":"2025-06-16T07:09:33.380Z","message":"incoming request"}
{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","book":{"ID":0,"CreatedAt":"0001-01-01T00:00:00Z","UpdatedAt":"0001-01-01T00:00:00Z","DeletedAt":null,"Title":"esse","Author":"pariatur voluptate ullamco est"},"timestamp":"2025-06-16T07:09:33.380Z","message":"usecase: creating book"}
{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","book":{"ID":0,"CreatedAt":"0001-01-01T00:00:00Z","UpdatedAt":"0001-01-01T00:00:00Z","DeletedAt":null,"Title":"esse","Author":"pariatur voluptate ullamco est"},"timestamp":"2025-06-16T07:09:33.380Z","message":"creating book"}
{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","book":{"ID":9,"CreatedAt":"2025-06-16T14:09:33.385135+07:00","UpdatedAt":"2025-06-16T14:09:33.385135+07:00","DeletedAt":null,"Title":"esse","Author":"pariatur voluptate ullamco est"},"timestamp":"2025-06-16T07:09:33.410Z","message":"book created successfully"}
{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","book":{"ID":9,"CreatedAt":"2025-06-16T14:09:33.385135+07:00","UpdatedAt":"2025-06-16T14:09:33.385135+07:00","DeletedAt":null,"Title":"esse","Author":"pariatur voluptate ullamco est"},"timestamp":"2025-06-16T07:09:33.410Z","message":"usecase: book created successfully"}
{"level":"INFO","request_id":"3383e6ee-8601-430d-86a8-e7018c8d4b1d","res":{"body":"{\"data\":{\"id\":9,\"title\":\"esse\",\"author\":\"pariatur voluptate ullamco est\"}}","method":"POST","path":"/books","process_ms":30,"status":201},"timestamp":"2025-06-16T07:09:33.411Z","message":"processed request"}

Config

New Options in .env

LOG_LEVEL=-1 # -1 -> 5
LOG_JSON=false # true / false

yokeTH added 9 commits June 16, 2025 13:18
- Add custom logger middleware using zerolog for structured logging
- Add request ID context injector middleware
- Replace Fiber's logger with new middleware in server setup
- Add zerolog-based logger package
- Remove custom Swagger handler in favor of gofiber-scalar/scalar
- Update go.mod and go.sum with new and upgraded dependencies
- Add LOG_LEVEL and LOG_JSON to env files
- Include .env in Air reload config
- Add golangci-lint to devShell in flake.nix
- Prefix messages with "Message:" for clarity
- Reduce stack trace depth from 32 to 16
- Return JSON error responses in ErrorHandler
@yokeTH yokeTH merged commit 41b960a into main Jun 16, 2025
2 checks passed
@yokeTH yokeTH deleted the feature/log branch June 16, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant