简体   繁体   中英

Is there a way to use `zerolog` logger in cadence workflows instead of `zap` logger?

I know that Cadence uses it's own internal non-exported context . That kind of makes it hard to get the values from it, as there is no conversion between workflow.Context and context.Context . But maybe there is another way I'm overlooking.

I don't think it is possible in Cadence. In Temporal you can inject any dependencies using interceptors . Also Temporal switched the logger to an interface , so you can use the exposed interface and write an adapter to the zerolog logger.

In Cadence you can use whatever logger you like in Activity including zerolog. For example we used our own fancy logger in Cadence system worker: https://github.com/uber/cadence/blob/11547ee6db5dd306cb507b263381a6ea94c3faf1/service/worker/scanner/history/scavenger.go#L34 https://github.com/uber/cadence/blob/11547ee6db5dd306cb507b263381a6ea94c3faf1/service/worker/scanner/history/scavenger.go#L286

It has strongly typed tags so that people can't make mistakes in putting tags.

But things are different in workflow. You definitely can't simply directly use you own logger in workflows. Because workflow can be replayed at any time. Cadence must ensure that logging is skiped during replying. Otherwise you may see weird logs.

So what end up happening if you want to use some other logger? The current answer is that you have to implement an interface. In Cadence you need to implement the zap.Core interface, and passing it when creating worker. In other words you can implement it using zerolog . But you can't directly using it in workflow code. You must use "workflow.GetLogger()".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM