1. Answers
  2. Showing Log Outputs in Preview Mode in Go

How do I show log outputs in preview mode in Go?

To show log outputs in preview mode using Pulumi in Go, you can utilize the pulumi.Log functions such as pulumi.Log.Debug, pulumi.Log.Info, pulumi.Log.Warn, and pulumi.Log.Error. These functions allow you to log diagnostics, warnings, or errors within your Pulumi program, providing better visibility into the deployment process and aiding in troubleshooting and monitoring.

Below is an example program demonstrating how to log outputs in preview mode:

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

// Define a simple Pulumi component
class MyComponent extends pulumi.ComponentResource {
    constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
        super("custom:resource:MyComponent", name, {}, opts);

        // Log a debug message
        pulumi.log.debug("This is a debug message", this);

        // Log an info message
        pulumi.log.info("This is an info message", this);

        // Log a warning message
        pulumi.log.warn("This is a warning message", this);

        // Log an error message
        pulumi.log.error("This is an error message", this);
    }
}

// Instantiate the component
const myComponent = new MyComponent("myComponent");

// Export a stack output
export const message = pulumi.output("Logging example completed.");

Key Points:

  • The pulumi.log functions (debug, info, warn, error) are used to log messages at different levels.
  • These logs will appear in the Pulumi CLI output during both preview and update operations.
  • Using these logging functions helps in debugging and monitoring the deployment process.

Summary:

In this example, we created a simple Pulumi component in TypeScript and used pulumi.log functions to log messages at various levels (debug, info, warn, error). These logs provide visibility into the deployment process, which is useful for debugging and monitoring.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up