powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Bug: Logger doesn't log to vscode debug terminal

Open Stefan-WW opened this issue 4 years ago • 4 comments

Hello,

While development, i run my code locally in vscode. But the lambda-powertools-logger doesn't log to the vscode debug terminal.

The following Code shows the Problem.

`

        const logger = new Logger({ serviceName: 'MyService', logLevel: 'DEBUG' });
        logger.debug('debug');
        logger.warn('warn');
        logger.error('error');
        logger.info('info');
        console.log('real logging');
        console.warn('real warning');
        console.info('real info');`

If i use console.log etc the Loggings are shown in the vscode debug terminal. But the logger from the powertools are not shown.

if i would add a small hack above: //@ts-ignore logger.console = console;

Then the loggings are shown in the debug terminal.

Expected Behavior

The Logs which are written, should be also shown in the vscode debug terminal.

Environment

  • Powertools version used: 0.9.1
  • Packaging format (Layers, npm): npm
  • AWS Lambda function runtime: nodejs

Stefan-WW avatar May 31 '22 20:05 Stefan-WW

@StefanVolkmer-WW thanks for opening the issue.

Could you please share your .vscode/launch.json or alternative clarify how you are executing the function? Would like to try to reproduce the issue.

dreamorosi avatar May 31 '22 21:05 dreamorosi

Hello @dreamorosi The Launch Config is the following: { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "launch", "program": "${workspaceRoot}/index.js", "preLaunchTask": "TypeScript->JavaScript" } ] }

You can reproduce it with a Standard Config. I created a Hello World Project: https://github.com/StefanV85/LambdaPowerToolsLoggerExample

Just Clone the Repository, run npm install Run the Launch Config.

StefanV85 avatar Jun 01 '22 07:06 StefanV85

Thanks for the config & sample repository, it's been really helpful.

I've looked into it and was able to reproduce the issue but I believe this is not a bug of Powertools Logger.

As you can see in this part of the Logger implementation, we output logs directly to process.stdout & process.stderr rather than simply using console.log - this change was made in #748 to have a cleaner output on AWS Lambda, which is the primary execution environment that we are targeting at the moment (see our project tenets here).

With that said, while looking at your repo I noticed that also something like process.stdout.write('something') was not showing up in the VSCode debug console. I then searched for existing issues on the VSCode repo and found this one https://github.com/microsoft/vscode/issues/19750.

In one of the comments, it is suggested to add an additional setting ("outputCapture": "std") to the Launch config like so:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "launch",
            "program": "${workspaceRoot}/index.js",
            "preLaunchTask": "TypeScript->JavaScript",
            "outputCapture": "std"
        }
    ]
}

See screenshot below that shows the new config, running your code, and with all the log outputs. Screenshot 2022-06-01 at 10 58 20

I'm going to be closing the issue and remove the bug label.

dreamorosi avatar Jun 01 '22 09:06 dreamorosi

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Jun 01 '22 09:06 github-actions[bot]