> On Apr 1, 2025, at 3:50 AM, robert engels <reng...@ix.netcom.com> wrote:
> 
> I don’t think this is that complicated. ...
> 
> slog already has the infrastructure to support additional handlers which I 
> think is all that is needed to support custom requirements - aka side effects 
> - of external libraries.

Hmm.  Okay. 

Then maybe you can help me understand how to handle something simple like 
getting an external package to use my handler vs. its hardcoded one? 

Below is single file that *simulates* the use-case of calling an external 
package with private loggers. As the developer of main() I would like to 
control the output handler for all loggers. Maybe I am just missing something 
obvious for how to accomplish this? 

func main() {
  myLogger := slog.New(slog.NewJSONHandler(os.Stdout,nil))
  slog.SetDefault(myLogger)
  slog.Default().Info("Yay my handler!")
  // Calling these functions simulates calling external package w/loggers
  otherFunction()
  thirdFunction()
}
var otherLogger = slog.New(slog.NewTextHandler(os.Stdout,nil))
func otherFunction() {
  otherLogger.Info("Not my handler. :-(")
}
func thirdFunction() {
  logger := slog.New(slog.NewTextHandler(os.Stdout,nil))
  logger.Info("Also not my handler. :-(")
}

Here it is in Go play: https://go.dev/play/p/Sqlny1oyRlS?v=

-Mike

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/0C52A6BF-BAC8-45E6-867D-43BAF68A719C%40newclarity.net.

Reply via email to