[GH-ISSUE #48] Log can be did using a better approach #17

Closed
opened 2026-02-26 04:33:46 +03:00 by kerem · 0 comments
Owner

Originally created by @mageddo on GitHub (Oct 16, 2017).
Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/48

The problem

Below reference links show that:

  • Every file/struct/function create your own log instance is not a good approach (as well it may cause concurrency problems), is better to just call a package function to log what you want
  • Save context in a struct is not a good approach
  • Just Println and debug are needle
  • Create a context with request is is not a log responsibility

Solution

  • Refactor go-logging API, eg.
    • Just call proxy go native log package and add Debug level
    • Use zap log tool and create an interface to overlap it
  • Create a context package to set and recover values from Context
  • Remove all logger instances and just reference it to a static function call

References

Originally created by @mageddo on GitHub (Oct 16, 2017). Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/48 ### The problem Below reference links show that: * Every file/struct/function create your own log instance is not a good approach (as well it may cause concurrency problems), is better to just call a package function to log what you want * Save context in a struct is not a good approach * Just Println and debug are needle * Create a context with request is is not a log responsibility ### Solution * Refactor go-logging API, eg. * Just call proxy go native log package and add Debug level * Use zap log tool and create an interface to overlap it * Create a context package to set and recover values from Context * Remove all logger instances and just reference it to a static function call ### References * https://dave.cheney.net/2015/11/05/lets-talk-about-logging * https://stackoverflow.com/questions/18361750/correct-approach-to-global-logging-in-golang * https://stackoverflow.com/questions/22758911/golang-does-logging-into-file-using-log-println-takes-care-of-concurrent-access
kerem 2026-02-26 04:33:46 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/dns-proxy-server-mageddo#17
No description provided.