🚀 Feature: Log levels #318

Closed
opened 2025-10-08 00:03:08 +03:00 by OVERLORD · 7 comments
Owner

Originally created by @mihakrumpestar on GitHub.

Feature description

It would be great if we could set container log level as currently GIN logs every single request, which in my home-lab produces almost 7,000 log entries per hour.

Pitch

I always set log level to warning, so I can clearly see if anything is wrong, as finding an error entry among 1000-ts of logs is a lot harder.

Originally created by @mihakrumpestar on GitHub. ### Feature description It would be great if we could set container log level as currently GIN logs every single request, which in my home-lab produces almost 7,000 log entries per hour. ### Pitch I always set log level to warning, so I can clearly see if anything is wrong, as finding an error entry among 1000-ts of logs is a lot harder.
OVERLORD added the open to pull requests label 2025-10-08 00:03:08 +03:00
Author
Owner

@mihakrumpestar commented on GitHub:

It is unset, as I checked the code where "production" is the default.

@mihakrumpestar commented on GitHub: It is unset, as I checked the code where "production" is the default.
Author
Owner

@mihakrumpestar commented on GitHub:

Well, GIN logs are completely irrelevant, and produce a ton of output.

I would appreciate a log level warning, where I can see if any problems arise, without any irrelevant info data like successful requests.

@mihakrumpestar commented on GitHub: Well, GIN logs are completely irrelevant, and produce a ton of output. I would appreciate a log level `warning`, where I can see if any problems arise, without any irrelevant info data like successful requests.
Author
Owner

@kmendell commented on GitHub:

@mihakrumpestar Correct prod is the default, even with that its still producing too many logs? I could maybe see a feature for a ENV varibale to disable logs if needed, but its usually good practice to keep those logs in the event of security issues or troubelshooting.

What logs are you trying not to see is a better question i guess?

@kmendell commented on GitHub: @mihakrumpestar Correct prod is the default, even with that its still producing too many logs? I could maybe see a feature for a ENV varibale to disable logs if needed, but its usually good practice to keep those logs in the event of security issues or troubelshooting. What logs are you trying not to see is a better question i guess?
Author
Owner

@kmendell commented on GitHub:

@mihakrumpestar What is your APP_ENV variable set too? It should cut down on logging if its set to: APP_ENV=production

@kmendell commented on GitHub: @mihakrumpestar What is your `APP_ENV` variable set too? It should cut down on logging if its set to: `APP_ENV=production`
Author
Owner

@kmendell commented on GitHub:

I dont see a default way to do this in GIN, unless you use the Skipper function, so if implemented, it would a be a bit of work. @stonith404 what are your thoughts?

@kmendell commented on GitHub: I dont see a default way to do this in GIN, unless you use the `Skipper` function, so if implemented, it would a be a bit of work. @stonith404 what are your thoughts?
Author
Owner

@stonith404 commented on GitHub:

@kmendell It seems like gin.New() creates a logging middleware. For supporting log levels we would have to create a custom logger.

I think this would make sense to implement but it's definitely not at the top of the priority list. But we are open for pull requests or upvotes (👍) which would prioritize the issue more.

@stonith404 commented on GitHub: @kmendell It seems like `gin.New()` creates a logging middleware. For supporting log levels we would have to create a custom logger. I think this would make sense to implement but it's definitely not at the top of the priority list. But we are open for pull requests or upvotes (👍) which would prioritize the issue more.
Author
Owner

@kklee998 commented on GitHub:

Seems like the default Gin logger does not support logging levels. How about using this logging middleware from gin-contrib:

Here is a rough sketch of the code:

// backend/internal/bootstrap/router_bootstrap.go

import (
        ....
	"github.com/gin-contrib/logger"
        ....
)


func initRouterInternal(db *gorm.DB, svc *services) (utils.Service, error) {
       ....
	r := gin.New()
	r.Use(gin.Recovery())
        // TODO: get the LOG_LEVEL from environment and call .SetLogger() with the correct config
	r.Use(logger.SetLogger()) 
       ....
}

Logs look like this:

Image

If you guys are okay with taking on an extra dependency, I can open a PR to properly implement this

@kklee998 commented on GitHub: Seems like the default Gin logger does not support logging levels. How about using this logging middleware from `gin-contrib`: Here is a rough sketch of the code: ```go // backend/internal/bootstrap/router_bootstrap.go import ( .... "github.com/gin-contrib/logger" .... ) func initRouterInternal(db *gorm.DB, svc *services) (utils.Service, error) { .... r := gin.New() r.Use(gin.Recovery()) // TODO: get the LOG_LEVEL from environment and call .SetLogger() with the correct config r.Use(logger.SetLogger()) .... } ``` Logs look like this: ![Image](https://github.com/user-attachments/assets/02ba4d84-6b54-47a4-b939-d02a5293a34c) If you guys are okay with taking on an extra dependency, I can open a PR to properly implement this
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id-pocket-id-1#318