Work with Lightrun Dynamic Logs in the JetBrains IDE¶
Prerequisites
To use the plugin, make sure you have:
- Installed the plugin in your local IntelliJ instance.
- Authenticated IntelliJ with your Lightrun account.
- Attached at least one agent to your app.
- Opened the source code file for the running application from the IDE.
Adding Logs¶
To insert a Dynamic Log into your code¶
- 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.
- Right-click to open the IntelliJ context menu.
- From the Lightrun context menu, select Log. The Create Log dialog should appear similar to the following image.
-
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 conditionmyVar % 7 == 0
limits the action (log, snapshot, metric) output so that it only prints for variables that are divisible by 7. -
Click Advanced to configure the following additional fields:
Fields Description Ignore Quota The quota (rate limit) is configured by the agent configurations.
Only users withIGNORE_QUOTA
role can override an agent's quota limitation, theIGNORE_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. -
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.
Right-click on the log marker to view more information about the log.
Click the log marker to edit or delete the log action.
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.
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.
- Go to the line in your application source code where you'd like to copy the log.
- Right-click on the log.
-
Click Copy to copy the log settings.
-
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.