sam logs output mangled
See original GitHub issueDescription
When I use sam logs
to view my lambda function logs from the console (OSX terminal) my log messages are mangled. Note, I don’t expect them to be pretty printed, but the output below is mangled.
2019/08/22/[$LATEST]57ae4b1bd8bf448d8e674d8231cc1970 2019-08-22T08:08:49.231000 START RequestId: ce26f5df-b0d9-4347-882a-cd89ccfc8160 Version: $LATEST
"body": "SiteCode=TSTSTE0001&TransactionId=7e1ea8de-c4a8-4a4e-b7d1-9d29e191bc46&TransactionReference=ABC123&Amount=100.99&Status=Complete&Optional1=&Optional2=&Optional3=&Optional4=&Optional5=&CurrencyCode=ZAR&IsTes "body": "SiteCode=TSTSTE0001&TransactionId=7e1ea8de-c4a8-4a4e-b7d1-9d29e191bc46&TransactionReference=ABC123&Amount=100.99&Status=Complete&Optional1=&Optional2=&Optional3=&Optional4=&Optional5=&CurrencyCode=ZAR&IsTest=} } "awsRequestId": "ce26f5df-b0d9-4347-882a-cd89ccfc8160"090357:function:centbee-ozow-api-OzowCallback",a5af86f6fec0b2c15e5df12f5f4b98084bcb5b621032e88a08b962d3a98ac226f84f9b748e"
} } "Hash": "28f7ebe65d84d2737cada8bbe31bc314430d00fd0d4ca726efd523a5af86f6fec0b2c15e5df12f5f4b98084bcb5b621032e88a08b962d3a98ac226f84f9b748e"fc8160 DEBUG {
'28f7ebe65d84d2737cada8bbe31bc314430d00fd0d4ca726efd523a5af86f6fec0b2c15e5df12f5f4b98084bcb5b621032e88a08b962d3a98ac226f84f9b748e' }-cd89ccfc8160 ERROR { message: 'Ozow callback hash check failed',
2019/08/22/[$LATEST]57ae4b1bd8bf448d8e674d8231cc1970 2019-08-22T08:08:49.943000 2019-08-22T08:08:49.943Z ce26f5df-b0d9-4347-882a-cd89ccfc8160 ERROR Hash check failed
2019/08/22/[$LATEST]57ae4b1bd8bf448d8e674d8231cc1970 2019-08-22T08:08:49.983000 END RequestId: ce26f5df-b0d9-4347-882a-cd89ccfc8160
2019/08/22/[$LATEST]57ae4b1bd8bf448d8e674d8231cc1970 2019-08-22T08:08:49.983000 REPORT RequestId: ce26f5df-b0d9-4347-882a-cd89ccfc8160 Duration: 751.81 ms Billed Duration: 800 ms Memory Size: 128 MB Max Memory Used: 96 MB
Here is the view from CloudWatch Management Console:
Steps to reproduce
I am producing these log messages like this (Node 10.x):
console.debug(JSON.stringify({ ozowResponse }, null, 2));
Observed result
See description above.
Expected result
I printed four log messages. Two console.debugs and two console.errors. I expect to see these four log messages as in the sam logs
output.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: OSX
sam --version
: 0.17.0
Add --debug flag to command you are running
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:24 (5 by maintainers)
Top Results From Across the Web
sam logs output mangled · Issue #1359 · aws/aws-sam-cli
Description When I use sam logs to view my lambda function logs from the console (OSX terminal) my log messages are mangled.
Read more >How do I see the full logs of a local invocation of a Lambda via ...
You can then see the logging in the terminal/command-prompt via. sam local start-api. Or have it log to a file with: sam local...
Read more >sam logs - AWS Serverless Application Model
Specifies the output format for logs. To print formatted logs, specify text . To print the logs as JSON, specify json . --cw-log...
Read more >Console.log output not appearing – AWS SAM Node.js
All of my node log output stopped appearing in my console locally. For now, there's a pretty simple workaround: 1. sam build --use-container ......
Read more >Deep Dive into AWS SAM - YouTube
Serverless Application Model ( SAM ) is a template driven tool for creating and managing serverless applications. In just a few lines of...
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 Reddit Thread
No results found
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
Hi there, I fixed the issue for us by adding
"test": "sam local invoke ... 2>&1 | tr \"\r\" \"\n\""
in our package.json script section.However, this issue has been opened for two years and it seems like it should be fixed, can you either give a reason not fix the issue and add a gentle note to the sam cli documentation (with that workaround), or fix it?
If not planning to fix, adding a note to the docs will save time to figure it out – many people like me could waste a lot of time thinking they are doing something wrong.
thanks
I take it back. I just downgraded to 1.3.0 and the issue is there. Anything with JSON.stringify will get mangled using local invoke. Can only see the fist line and the last line. So anything with \n or \r will not work. For example.
console.log('line one\rline two\rline three\nline four\nline five')
will output
Should I start a new issue for this or can this issue be re-opened?
Edit:
sam local invoke 2>&1 | tr "\r" "\n"
will work with no other code changeprocess.stdout.write()
will also work but one must change every console.log call@mhart the above code will work but this is still a bug and should be re-opened.