开源包mqtt源码_DEBUG

2021/8/18 11:06:04

本文主要是介绍开源包mqtt源码_DEBUG,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

开源包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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程