logging strings with line breaks prints multiple messages in cloudwatch
See original GitHub issueHi there,
When I print a message with line breaks in it like this
nlogLogger.Info(@"nlog line
breaks
see how it
handles this");
LambdaLogger.Log(@"lambda logger line
break
see how
it handles it");
Console.WriteLine(@"long line
see how console write
handles it");
It looks like this in cloudwatch
I’ve tried using nlog, lambda’s built in logger, and simple console.writes
I’m using a self contained 3.1 .netcoreapp using Amazon.Lambda.AspNetCoreServer 4.1.0 Is this intended behavior or a side-effect or running as a self contained app? Are there any work around like setting line breaks somehow at the logger level?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
New line problem in CloudWatch output when logging with ...
I have the problem, that when logging with slf4j (and io.symphonia:lambda-logging) in Java, for every new line in the logging message ...
Read more >Concatenate multiline or stack-trace log messages
The multiline filter helps concatenate log messages that originally belong to one context but were split across multiple records or log lines.
Read more >How Multi-Line Logging Works in Lambda -> CloudWatch
Multi -line logging is an essential technique for generating detailed logs in Lambda functions. By default, Lambda functions log each message on ...
Read more >AWS Lambda in Java 8, log4j2 and scattered stack trace in ...
The issue: when logging stack trace to standard output with one of standard loggers, stack trace is nicely formatted with newlines.
Read more >Ben Kehoe
Periodic reminder for a CloudWatch Logs protip: replace newlines with carriage returns ('\r') in your multi-line log messages (e.g., ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would be the same principle, you need to replace all \n with \r
If you are using standard MS logging you will need to write your own logger.
https://stackoverflow.com/questions/44230373/is-there-a-way-to-format-the-output-format-in-net-core-logging
Hi @RMarinaro,
Good evening.
Thanks for posting the guidance question. Based on my research while going through various blogs/articles, any string after the new line character ‘
\n
’ (even ‘\n\r
’ for DOS based systems) is split to the next entry in CloudWatch Logs. The below string has 4 new line characters:And hence CloudWatch splits this into 4 separate entries. Unfortunately, it appears that this behavior is controlled by CloudWatch. The workaround is to convert new line character ‘
\n
’ (and/or ‘\n\r’) to carriage return ‘\r
’, in which case, the CloudWatch would group the multi-line string into one entry.Please let me know if this guidance helps and let me know if this issue could be closed.
Thanks, Ashish