Skip to content

Conversation

@despairblue
Copy link
Contributor

@despairblue despairblue commented May 27, 2025

Summary

  • allow logging json to the console
  • allow logging errors

Before this we would always log text to stdout, which is sub-optimal for production use cases because we loose all of the metadata that log ingestion systems could use:

  • there is no log level apart from error and info
  • all metadata is lost (unless they are inlined in the message, e.g. workflow and execution IDs)
  • especially error stack traces are lost

This PR adds a new environment variable to change the log's output format N8N_LOG_FORMAT. It can be set to default and json and defaults to default, which is the current text based output.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/PAY-2779/allow-logging-json-to-stdout

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/active-workflow-manager.ts 66.66% 1 Missing ⚠️
...es/core/src/instance-settings/instance-settings.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels May 27, 2025
@despairblue despairblue force-pushed the pay-2779-allow-logging-json-to-stdout branch from 1723aa5 to c21e7cd Compare May 30, 2025 13:10
@despairblue despairblue marked this pull request as ready for review May 30, 2025 13:23
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 1 issue across 4 files. Review it in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

Comment on lines 116 to 122
for (const key of Object.keys(metadata)) {
const value = metadata[key];
if (value instanceof Error) {
metadata[key] = this.detailedErrorStringify(value);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be reasonable to expect the key to be called error so we don't have to check every key in every metadata object in every log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather be safe than sorry. But we should probably adhere to that pattern. I think we could write an eslint rule for that, but that's out of scope for this PR.

@despairblue despairblue force-pushed the pay-2779-allow-logging-json-to-stdout branch from 3cd87ce to 9b920d4 Compare June 2, 2025 14:01
@despairblue despairblue requested a review from ivov June 2, 2025 14:01
Copy link
Member

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing everything!

Asked about the single-line logs here to confirm.

@shortstacked
Copy link
Contributor

Workflow Test Results 📊 🔴 1 Failed, ⚠️ 3 Warnings, 👍 79 Successful out of 83 total workflows.

Detail: Workflows failing: 237: Workflow contains 1 deleted data. View full workflow run

Tested Ref: 9b920d49205744d852248bdd2d2f3f10b64f1c49 by @ivov

❌ Failed Tests (1)

Workflow ID Workflow Name Reason
237 BasicLLMChain:AzureChat Workflow contains 1 deleted data.

⚠️ Warnings (3)

Workflow ID Workflow Name Reason
35 Slack:User:getPresence info:UserProfile:get update... Workflow contains new data that previously did not exist.
257 Agent:auto-fix:anthropic Workflow contains new data that previously did not exist.
53 ConvertKit:CustomField:create getAll update delete... Workflow contains new data that previously did not exist.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2025

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit 8abd556 into master Jun 3, 2025
13 checks passed
@despairblue despairblue deleted the pay-2779-allow-logging-json-to-stdout branch June 3, 2025 08:42
Alexandero89 pushed a commit to Alexandero89/n8n that referenced this pull request Jun 4, 2025
Alexandero89 pushed a commit to Alexandero89/n8n that referenced this pull request Jun 4, 2025
@janober
Copy link
Member

janober commented Jun 11, 2025

Got released with n8n@1.98.0

TianYi0217 pushed a commit to TianYi0217/n8n that referenced this pull request Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants