Working with logpoints

Once you have set up debugging in Stackdriver Debugger and have deployed and/or started your application, you can add logpoints in the source console.

Logpoints

Logpoints allow you to inject logging into running services without restarting or interfering with the normal function of the service. Every time any instance executes code at the logpoint location, Stackdriver 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 Stackdriver 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 left panel of the console, browse to the file that contains the source where you want to add the logpoint.

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

    Select logpoint location

  3. Select the application where you want to add the logpoint when prompted.

    Select logpoint application

  4. Click Create Logpoint.

    Create logpoint

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

    Create logpoint

  6. Click Add.

After you add a logpoint, the expression appears inline in the file view in the source console. To edit the logpoint, hover over it and click the pencil icon.

Logpoint conditions

A logpoint condition is a simple expression in the application language that must evaluate to true for the logpoint to be logged. Logpoint conditions are evaluated each time the line is executed, by any instance, 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 allow you to 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 Stackdriver Logging.

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

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 can be configured to write to a specific file.

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

Deleting logpoints

Logpoints become inactive and stop logging messages after 24 hours, and are automatically deleted after 30 days. You can manually delete logpoints, which both stops the logging and removes it from the history for future reference. Note that, however, deleting a logpoint does not delete the log messages already generated.

To delete a logpoint, hover over it in the Logpoints tab in the bottom panel of the console and click the trash can icon.

Delete logpoint

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Source Repositories