1

I am using the Typescript API of pulumi. I noticed that when I invoke console.log("\n\n"), pulumi strips out the newlines. I want to keep these newlines to improve the readability of the deployment log.

Is there a way to instruct pulumi to keep newlines in the output log?

Gili
  • 86,244
  • 97
  • 390
  • 689

2 Answers2

2

The current behavior of the Pulumi CLI is to break your messages into lines (split by \n), trim every line, drop empty lines, and display the result.

Although ugly, you could force your line breaks with an extra "zero-width space" character:

console.log("Top line");
console.log("\u200B\n\u200B\n\u200B");
console.log("There will be three empty lines before this line");

You could use something more trivial like _ instead of the zero-width space. Obviously, underscores will be visible.

Track this issue for further progress.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
1

Pulumi should not be stripping newlines or otherwise manipulating your console.log() output. I just tested this and my string with newlines was printed as expected with newlines.

Code

import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("main", {
    acl: "private",
})

bucket.onObjectCreated("logger", new aws.lambda.CallbackFunction<aws.s3.BucketEvent, void>("loggerFn", {
    memorySize: 128,
    callback: (e) => {
        for (const rec of e.Records || []) {
            const [buck, key] = [rec.s3.bucket.name, rec.s3.object.key];
            console.log(`Object created: ${buck}/${key}`);
        }
    },
}));

console.log(`My 
multi-line
string`);

export const bucketName = bucket.bucket;

Output

$ pulumi up -y
Previewing update (dev):

     Type                                  Name                        Plan       Info
 +   pulumi:pulumi:Stack                   demo-aws-ts-serverless-dev  create     3 ...
 +   └─ aws:lambda:Function                loggerFn                    create

Diagnostics:
  pulumi:pulumi:Stack (demo-aws-ts-serverless-dev):
    My
    multi-line
    string

Resources:
    + 8 to create

Updating (dev):

     Type                                  Name                        Status      Info
 +   pulumi:pulumi:Stack                   demo-aws-ts-serverless-dev  created     ...
 +   └─ aws:lambda:Function                loggerFn                    created

Diagnostics:
  pulumi:pulumi:Stack (demo-aws-ts-serverless-dev):
    My
    multi-line
    string

Outputs:
    bucketName: "main-b568df3"

Resources:
    + 8 created

...
Cameron
  • 431
  • 3
  • 3
  • It seems my question was not clear enough. I want to add empty lines in the output. Your example works because every line contains some text. However, the following will not work: `console.log("first"); console.log("\n\n\n\n\n"); console.log("second");` I am expecting multiple newlines between `first` and `second`. In actuality, I get no space between the two lines. – Gili Sep 04 '19 at 15:43
  • 1
    Yes, that's different than what I tried. I've opened https://github.com/pulumi/pulumi/issues/3180 to address this. – Cameron Sep 04 '19 at 18:29