donnie4w / tklog

lightweight and efficient rust structured log library with support for log levels, file segmentation, compressed archiving
https://crates.io/crates/tklog
Apache License 2.0
58 stars 4 forks source link

使用 log 库的宏打印日志与使用 tklog 中的宏异步打印日志会有什么区别么 #7

Open Tianion opened 2 weeks ago

Tianion commented 2 weeks ago

RT,这中间会有什么性能损耗么

donnie4w commented 2 weeks ago

@Tianion 两者没有区别 通过tklog中设置 ASYNC_LOG.uselog() 来启用标准库API,实际上是把标准库的执行实例设置为 异步对象 ASYNC_LOG。 它们差异非常小,可以认为没有差别。

它们的大概的差别是: 标准库会多几条判断指令;另外标准库会将一些参数事先获取。文件名行号等。如果你设置的日志库格式没有文件名行号,那么直接调tklog宏,比如tklog::async_debug! 则不会获取这些参数。但调用 log::debug!时,标准库还是会先获取这些参数,传递给tklog。 但是这些差异对性能影响非常小,即使高并发场景也不会表现出明显的性能差异。