Skip to content

Work with Lightrun Dynamic Logs in the JetBrains IDE

Prerequisites

To use the plugin, make sure you have:

  1. Installed the plugin in your local IntelliJ instance.
  2. Authenticated IntelliJ with your Lightrun account.
  3. Attached at least one agent to your app.
  4. Opened the source code file for the running application from the IDE.

Adding Logs

To insert a Dynamic Log into your code
  1. Go to the line in your application source code where you'd like to insert the log. Make sure to use the source code version currently deployed to production.
  2. Right-click to open the IntelliJ context menu.
  3. From the Lightrun context menu, select Log. Context Menu -half The Create Log dialog should appear similar to the following image. Create Log -half
  4. Complete the fields in the dialog as follows:

    Fields Description
    Source From the available options in the dropdown list, bind the action to a specific agent, tag, or custom source.
    Click Create Custom Source to create a new custom source.
    Filename & Line The source code file into which you're inserting the action. The default path is to the source code file from which you're currently working.
    Format The actual log string. Use expressions such as My variable is {var}, including method invocations such as: Method value: {myMethod() + 5}.
    Targets Select your preferred action output target. You can pick either:
    - Stdout - Logs are routed only to your application's standard output.
    - Plugin - Logs appear in the Lightrun Console, the Lightrun Management Portal, and configured integrations.
    or both options at once.
    Condition The condition of an if statement, used to limit the execution of the action.
    For example, The condition myVar % 7 == 0 limits the action (log, snapshot, metric) output so that it only prints for variables that are divisible by 7.
  5. Click Advanced to configure the following additional fields:

    Fields Description
    Ignore Quota The quota (rate limit) is configured by the agent configurations.
    Only users with IGNORE_QUOTA role can override an agent's quota limitation, the IGNORE_QUOTA checkbox is disabled for other users.
    Expiry The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
    Level Select an appropriate log level: INFO, ERROR, DEBUG, WARN.
    Once configured, logs can also be filtered by the LOG LEVEL attribute in the Lightrun console.
  6. Click Save to add the log to your code.

Managing Logs

Once a log action has been inserted into your code, a log marker should appear on the code line where the action was added.

Log marker --half

Right-click on the log marker to view more information about the log.

Log marker --half

Click the log marker to edit or delete the log action.

Log delete --half

Analyzing logs

Lightrun dynamic logs and metrics, by default, are printed into the application’s standard output(Stdout). This process enables them to be analyzed in the context of pre-existing logs or metrics, which might provide further clues towards solving issues.

At the same time, you can also configure your action target to Plugin. This configuration lets you view your dynamic logs and metrics output directly in your IDE through the Lightrun Console, the Lightrun Management Portal, and third-party integrated apps like Slack or Prometheus.

Viewing logs and metrics from the JetBrains Lightrun Console

Once you've configured your action target to Plugin and added at least one dynamic log or metric to your code, the Lightrun Console should display real-time output from the added dynamic log or metric.

The Lightrun Console
The Lightrun Console

See JetBrains plugin quick tour to learn more about the Lightrun Console tool window.

To copy and paste a dynamic log into your code

This procedure allows you to easily reuse existing logs in multiple locations within your code. Note that the log is saved in the clipboard and can be pasted multiple times.

  1. Go to the line in your application source code where you'd like to copy the log.
  2. Right-click on the log.
  3. Click Copy to copy the log settings.

    Log copy --half

  4. Go to the line of your target source code at which you'd like to insert the copied log, right-click and click Paste Log. Log copy --half


Last update: December 4, 2024