Skip to content
Discussion options

You must be logged in to vote

You do not need to escape the JSON. Pass it as a placeholder value instead of putting it directly into the message template:

const message = {
  messageKind: "Monitor",
  delta: { a: "aaa" },
};

logger.info("message is {json}", {
  json: JSON.stringify(message),
});

The braces inside json are data, so LogTape does not parse them again. Only the first string ("message is {json}") is parsed as the message template.

Even better, keep the object structured and let the configured formatter render it:

logger.info("message is {message}", { message });

Or, if you do not need a text message at all:

logger.info({ message });

That preserves messageKind and delta as structured data for JSON sinks, f…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@joswarmer
Comment options

Answer selected by joswarmer
Comment options

You must be logged in to vote
1 reply
@paulodearaujo
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants