英文:
How set a new one function to know when another function is calling?
问题
我正在一个 Go 语言项目中工作。我的目标是创建一个日志记录包,在执行某些预配置的函数时使用日志记录。
我不想在每个函数中调用我的日志记录函数,而是想定义我想要自动记录的函数调用。
英文:
I'm working in a Go lang Project. My goal is creating a logging package logging use of some pre-configured functions when they are executed.
I don't want call my logging function in each one, instead I want to define what function calls I want to have logged automatically.
答案1
得分: 3
你无法仅使用Go完成这个任务。你需要预处理你的Go源代码,并指示预处理器在需要的地方包含日志记录。可以参考go test -cover
命令是如何进行这种重写的。
英文:
You cannot do this in Go alone. You would have to preprocess your Go source code and instruct the preprocessor to include logging wherever you want. Take a look at how go test -cover
does such kind of rewriting.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论