1 ---
2 sidebar_label: "no-console-log-in-workflow"
3 ---
4
5 export const metadata = {
6 title: `no-console-log-in-workflow - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule disallows `console.log` and other `console.*` calls directly inside a `createWorkflow` constructor or a `when().then()` callback.
12
13 ## Severity
14
15 `warn`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets files in your project's `src/workflows` directory. It reports `console.*` calls placed directly in a workflow's constructor or in a `when().then()` callback.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/workflows/example.ts"
24 import {
25 createWorkflow,
26 WorkflowResponse,
27 } from "@medusajs/framework/workflows-sdk"
28
29 createWorkflow("my-workflow", (input) => {
30 console.log("definition-time")
31 return new WorkflowResponse(input)
32 })
33 ```
34
35 Instead, move logging into a `createStep` callback:
36
37 ```ts title="src/workflows/example.ts"
38 import {
39 createWorkflow,
40 createStep,
41 WorkflowResponse,
42 } from "@medusajs/framework/workflows-sdk"
43
44 const logStep = createStep("log", (input) => {
45 console.log("execution-time")
46 })
47
48 createWorkflow("my-workflow", (input) => {
49 logStep(input)
50
51 return new WorkflowResponse(input)
52 })
53 ```
54
55 ## Why it's Important
56
57 A workflow's constructor and `when().then()` callbacks run at definition time, not execution time. So, a `console.*` call there only logs when the workflow is registered, not on each execution. Move logging into a `createStep` callback so it runs every time the workflow executes.
58
59 Learn more in the [Debugging Workflows documentation](!docs!/learn/debugging-and-testing/debug-workflows).
60
61 ## Fixable
62
63 This rule isn't auto-fixable.
64
65 ## Turn it Off
66
67 To turn off this rule, set it to `off` in your ESLint configuration:
68
69 ```ts title="eslint.config.ts"
70 import { defineConfig } from "eslint/config"
71 import medusa from "@medusajs/eslint-plugin"
72
73 export default defineConfig([
74 ...medusa.configs.recommended,
75 {
76 rules: {
77 "@medusajs/no-console-log-in-workflow": "off",
78 },
79 },
80 ])
81 ```
82
83 Or disable it for a single line using an inline comment:
84
85 ```ts
86 // eslint-disable-next-line @medusajs/no-console-log-in-workflow
87 console.log("definition-time")
88 ```