spf13 / viper

Go configuration with fangs
MIT License
27.03k stars 2.01k forks source link

Add an option to make viper spit out debug output #1152

Open zneix opened 3 years ago

zneix commented 3 years ago

Is your feature request related to a problem? Please describe. I am in the process of implementing viper as configuration manager for my Golang project. While debugging, I've found it very hard to notice why does viper not want to read my config files and it turned out I specified wrong config path in my code - I wouldn't figure this out if I didn't change jww's output level in viper's source code. I find it highly problematic in some cases to not have any option to get debug output for viper without having to modify its source.

Describe the solution you'd like to see A method like viper.SetLogLevel() / viper.BeVerbose() or something along these lines, could be useful while working with viper as explained in my case above.

Describe alternatives you've considered Modifying viper's source code and using git reset --hard every time you're done debugging.

Additional context N/A

github-actions[bot] commented 3 years ago

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

vietvudanh commented 3 years ago

I was frustrating with this too. As I can see, viper is using jww for logging, but I cannot see how to enable it yet.

tatablack commented 2 years ago

I agree, it would be nice to have some global setting (e.g. an environment variable) to define Viper's default logging level.

As a workaround (as @vietvudanh noticed), it's possible to set jww's logging level from your own code, without touching Viper's source (check jww's own README for more details:

import (
    jww "github.com/spf13/jwalterweatherman"
)

jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelTrace)
vietvudanh commented 2 years ago

I agree, it would be nice to have some global setting (e.g. an environment variable) to define Viper's default logging level.

As a workaround (as @vietvudanh noticed), it's possible to set jww's logging level from your own code, without touching Viper's source (check jww's own README for more details:

import (
  jww "github.com/spf13/jwalterweatherman"
)

jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelTrace)

I ended up with setting log level in my config file, then using code to set jww threshold.