首页 > 其他 > 详细

开源包mqtt源码_DEBUG

时间:2021-08-18 15:45:21      阅读:22      评论:0      收藏:0      [点我收藏+]

开源包mqtt源码_DEBUG

巧妙的调试不注释变量

官方代码包

type (
	// Logger interface allows implementations to provide to this package any
	// object that implements the methods defined in it.
	Logger interface {
		Println(v ...interface{})
		Printf(format string, v ...interface{})
	}

	// NOOPLogger implements the logger that does not perform any operation
	// by default. This allows us to efficiently discard the unwanted messages.
	NOOPLogger struct{}
)

func (NOOPLogger) Println(v ...interface{})               {}
func (NOOPLogger) Printf(format string, v ...interface{}) {}

// Internal levels of library output that are initialised to not print
// anything but can be overridden by programmer
var (
	ERROR    Logger = NOOPLogger{}
	CRITICAL Logger = NOOPLogger{}
	WARN     Logger = NOOPLogger{}
	DEBUG    Logger = NOOPLogger{}
)

分析

看这个项目时候总是有这样的代码 DEBUG.Println(CLI, "client is connected/reconnected"), 但是进到源码一看啥都没打印

在自己写项目时候,总是会调试一些东西,有些变量我们会用fmt打印出来,但是不想让变量打印,还要注释上面的var定义,很麻烦,就要用一个空接口来接受我们的需要注释的变量,这个设计很巧妙

果断把他抄作业,带走到我的go-utils工具包里面去

开源包mqtt源码_DEBUG

原文:https://www.cnblogs.com/maomaomaoge/p/15155837.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!