go-kit 入门(三)日志和仪表化




任何需要日志记录的组件都需要将 logger 作为依赖,就像数据库连接一样。因此,我们在 main 函数中构造 logger 对象,然后将其传入需要使用它的组件中。我们始终不去使用一个全局的 logger 对象。

我们可以直接将 logger 传入到 stringService 的实现代码中,但是,还有一个更好的方式。我们可以使用 中间件 (middleware) ,也常常被称为 装饰者。

middleware 是一个函数,它接收一个 endpoint 作为参数,并且返回一个 endpoint。



事实证明,这项技术是非常有价值的,远远不止于记录日志,Go kit 的很多模块都被实现为端点中间件。


那么,在我们的应用中,应该如何记录日志呢?比如那些需要被传入的参数等。事实上,我们能够为我们的服务定义一个中间件,从而获得同样好的组合效果。由于我们的 StringService被定义为一个接口,我们只需要作出一个新的类型,来包装先有的 StringService,让它来执行扩充的记录日志的任务。




在 Go kit 中,仪表化意味着使用 包指标 来记录关于服务运行行为的状态。统计执行的任务的数量,在请求完成后记录消耗的时间,以及跟踪所有正在执行的操作的数量,都被认为是 仪表化。




目前位置,完整的服务是 stringsvc2.

此条目发表在GoLang, MircroService分类目录。将固定链接加入收藏夹。

go-kit 入门(三)日志和仪表化》有 478 条评论

  1. One extra technique in support of advertising your website is posting comments on different sites with your website link.

  2. What’s up, just wanted to tell you, I liked this article. It was inspiring. Keep on posting!

  3. Your mode of describing all in this paragraph is truly pleasant, all can simply know it, Thanks a lot.

  4. Hello, how’s it going? Just shared this post with a colleague, we had a good laugh.

  5. Hello, just wanted to say, I loved this blog post. It was practical. Keep on posting!

  6. Hi there to every , because I am in fact eager of reading this webpage’s post to be updated regularly. It consists of good stuff.

  7. Can you tell us more about this? I’d love to find out more details.

  8. Hurrah, what a quality it is! As mostly YouTube video clips have no nice feature, except this is truly a pleasant quality video.

  9. If you are interested to learn SEO techniques then you have to read this article, I am sure you will take much more from this piece of writing about Search engine marketing.

  10. You have to waste less time to search your required topic on web, because nowadays the searching techniques of search engines are good. That’s why I fount this article here.

  11. What’s up, okay brother there are of course multiple blogging websites, however I suggest you to use Google’s without charge blogging services.

  12. This is my first time go to see at here and i am truly happy to read all at single place.

  13. I all the time download a complete film in parts, that’s always present at YouTube, for the reason that my network connection is extremely slow and YouTube fulfils my needs.

  14. This text is priceless. When can I find out more?

  15. Vohycle说:

    buy cheap generic cialis i
    cheap cialis
    price for cialis online pharmacy
    =http://buyhcialisrx.com/#”>cialis online

  16. Every weekend i used to go to see this website, as i wish for enjoyment, since this this site conations really pleasant funny data too.

  17. Hi there to every body, it’s my first visit of this webpage; this blog includes awesome and actually excellent data for readers.

  18. Endeark说:

    get cialis online
    buy cialis online
    walmart cialis online pharmacy
    =http://buyhcialisrx.com/#”>generic cialis

  19. cheap viagra说:

    What’s up everyone, I am sure you will be enjoying here by watching such comical video clips.

  20. What’s up to all, how is everything, I think every one is getting more from this web page, and your views are pleasant in favor of new users.

  21. Hello, how’s it going? Just shared this post with a colleague, we had a good laugh.

  22. YouTube is world’s leading video sharing web site, no one can defeat it. Every one add video clips at YouTube after that get embed code and post everywhere.

  23. always i used to read smaller content which as well clear their motive, and that is also happening with this article which I am reading at this time.

  24. Every weekend i used to go to see this site, because i wish for enjoyment, for the reason that this this website conations truly fastidious funny stuff too.

  25. I have read much concerning free of charge blogging sites, except I have no clear idea about that, can any one inform me which one is most excellent for free blogging and site-building?

  26. When someone writes an article he/she keeps the thought of a user in his/her mind that how a user can know it. Thus that’s why this article is great. Thanks!

  27. sildenafil说:

    Some viewers are eager to watch comical videos, however I like to watch terrible movies on YouTube.

  28. YouTube is world’s leading video sharing web page, no one can defeat it. Every one upload video tutorials at YouTube then obtain embed code and post anywhere.


电子邮件地址不会被公开。 必填项已用*标注