Working with logpoints

Stay organized with collections Save and categorize content based on your preferences.

After you set up debugging in Cloud Debugger and deploy or start your app, you can add logpoints in the source console.

Logpoints overview

Logpoints let you inject logging into running services without restarting or interfering with the normal function of the service. Every time any instance runs code at the logpoint location, Debugger logs a message. The log output is sent to the appropriate log for the target environment. For App Engine, for example, output is sent to the request log in Cloud Logging.

Logpoints remain active for 24 hours after creation, or until they are deleted or the service is redeployed.

Adding a debug logpoint

  1. In the Google Cloud console, open Cloud Source Repositories.

    Open Cloud Source Repositories

    The All repositories page opens. Alternatively, you can open the My source view.

  2. Click the name of a repository.

  3. Go to the file that contains source code you want to watch.

  4. Click the line number of the source code location.

    Select logpoint location

  5. When prompted, select the app where you want to add the logpoint.

    Select logpoint application

  6. Click Create logpoint.

    Create logpoint

  7. Where prompted, enter the logpoint condition and message.

    Create logpoint

  8. Click Add.

    After you add a logpoint, the expression appears inline in the file view in the source console. To edit the logpoint, hold the pointer over it and click Edit .

Logpoint conditions

A logpoint condition is a simple expression that must evaluate to true for the logpoint to be logged. Logpoint conditions are evaluated each time an instance runs the line of code until the logpoint expires or is deleted.

The condition is a full boolean expression that can include logical operators:

travelAccessory == "Towel"
ultimateAnswer <= 42
travelAccessory == "Towel" && ultimateAnswer <= 42

Logpoint messages

The message of a logpoint determines what gets logged in the output. Expressions let you evaluate and log values of interest. Anything in the message between curly braces, such as {myObj.myFunc()} or {a + b}, is replaced with the value of that expression in the output. The message User {name} scored {newScore.score} in the example above logs output similar to User user1 scored 99.

You can use the following language features for expressions.

Java

Most Java expressions are supported, including:
  • Local variables: a == 8.
  • Numerical and boolean operations: x + y < 20.
  • Instance and static fields: this.counter == 20, this.myObj.isShutdown, myStatic, or com.mycompany.MyClass.staticMember.
  • String comparisons with the equality operator: myString == "abc".
  • Function calls. You can use read-only functions only. For example, StringBuilder.indexOf() is supported, but StringBuilder.append() is not.
  • Type casting, with fully qualified types: ((com.myprod.ClassImpl) myInterface).internalField.

The following language features are not supported:

  • Unboxing of numeric types, such as Integer; use myInteger.value instead.

Python

Most Python expressions are supported, including:
  • Reading local and global variables.
  • Reading from arrays, lists, slices, dictionaries, and objects.
  • Calling simple methods.

The following language features are not supported:

  • Calling functions that allocate new objects or use complex constructs.
  • Creating new objects inside the expression.

Go (Beta)

Most Go expression syntax is supported, including:
  • Reading local and global variables.
  • Reading from arrays, slices, maps, and structs.

The following language features are not supported:

  • Reading from interface values.
  • Type conversions and composite literals.
  • Function calls other than len.

Viewing output

Logpoint output is sent to the appropriate log for the target's environment.

App Engine

Logpoints set on App Engine apps send their output to the request log in Logging.

You can view the logs in the Logs Panel or in the dedicated Logs Explorer.

Compute Engine

Logpoints set on Compute Engine apps send their output to the same location as regular log statements. For example, in Python, the default logging module sends its output to stdout, but it can be configured to write to a specific file.

You can set up the logging agent to forward these logs to Logging. From there, you can view the logs in the Logs Explorer.

Deleting logpoints

Logpoints become inactive and stop logging messages after 24 hours, and they are automatically deleted after 30 days. You can manually delete logpoints, which both stops the logging and removes the logging from the history for future reference. However, deleting a logpoint doesn't delete the log messages already generated.

To delete a logpoint, follow this process:

In the Logpoints tab in the bottom pane of the GCP Console, hold the pointer over the logpoint, and then click Delete

Delete logpoint

What's next