How to implement level based logging in golang?

前端 未结 11 1912
谎友^
谎友^ 2020-12-24 04:44

Is there any good wrapper available for level based logging in golang? If not, how should I go about implementing one myself?

What I want is pretty simple. I want a

相关标签:
11条回答
  • 2020-12-24 05:23

    I am working with rlog at the moment and like their approach. The code looks good, simplistic and sufficiently documented.

    What convinced me:

    • no external dependencies
    • i can use rlog.Info() anywhere without passing around references
    • good usage of environment variables
    • arbitrary number of trace levels e.g. rlog.Trace(4, "foo")
    0 讨论(0)
  • 2020-12-24 05:24

    I think seelog fits your requirements, and it seems to be pretty popular as it pops up often in log discussions. I never used it seriously, so I can't comment beyond that.

    0 讨论(0)
  • 2020-12-24 05:26

    https://github.com/hashicorp/logutils I found this to be very easy to use and you don't even need to change the method calls to log.Printf of the std library.

    0 讨论(0)
  • 2020-12-24 05:27

    Here's a nice article, that basically says that you don't need level based logging. I feel that it's maybe too opinionated, but it also worths to read a different perspective.

    0 讨论(0)
  • 2020-12-24 05:33

    You can use the module midlog to implements any other log library, https://github.com/lingdor/midlog

    0 讨论(0)
提交回复
热议问题