Search code examples
cadence-workflow

What’s the best way to log messages from Cadence workflows and activities?


In my workflows and activities, I’d like to log some messages for debugging purposes.

I saw the cadence.GetLogger(ctx).Info() function, but don’t know where to find the logs.


Solution

  • Go Client:

    You can use the following in the workflow code:

    cadence.GetLogger(ctx).Info(...)
    

    In the activity code, you should use the following:

    cadence.GetActivityLogger(ctx).Info(...)
    

    By default, the logger will write to console, which may be sufficient for development purposes. However, you should log to a file if you need the logs in production, too. Here is how to setup your cadence worker to do it:

    workerOptions := cadence.WorkerOptions{
     Logger: myLogger, 
    } 
    worker := cadence.NewWorker(service, domain, taskList, workerOptions)
    

    The Cadence client uses zap as the logging framework. You can create the zap logger and specify the log file path per your needs. Check out the zap documentation to learn more about configuring the logs.

    Java Client

    The Java client uses slf4j for logging. You can get the logger instance by calling Workflow.getLogger() and configure it in logback.xml as usual.