phuslu / log

Fastest structured logging
MIT License
672 stars 44 forks source link

fix EventlogWriter init err memorizing #82

Closed xuyang2 closed 3 months ago

xuyang2 commented 3 months ago

Should fix #83

phuslu commented 3 months ago

I see.

But I think we need resolve this issue by another way, would you think this approach ( in syslog writer) is more reasonable?

https://github.com/phuslu/log/blob/master/syslog.go#L80-L90

xuyang2 commented 3 months ago

我觉得把 RegisterEventSource 写成这种 ensureRegisterEventSource() 的形式没什么意义 (不像 ensureConnection() 可能要处理重连) 很适合用 sync.Once

phuslu commented 3 months ago

之所以倾向 double lock checking 的好处是它这种方式存在“自愈”的可能。

比如外部依赖(syslog server, windows event servcie)一段时间持续不可用,double lock checking 的方式可以一直报错+尝试,在外部依赖恢复之后也能初始化成功,而不用重启程序。

phuslu commented 3 months ago

不想用 NewXXXWriter 的风格,因为我在使用zerolog过程中,觉得过程式(flunt API)的构造反而繁琐且不直观。

还是像标准库 http.Transport{} 这种指定很多选项构造比较直观,所以就一直保留了下来。