Dynamic Logs¶
Prerequisites
To use the plugin, make sure you have:
- Attached an agent to your application
- Installed the plugin in your local VSCode instance
- Authenticated the VSCode plugin against your Lightrun account
- The source code file for your running application is opened in VSCode
From the Lightrun plugin for VSCode, you can:
Adding logs¶
To add dynamic logs to your code, you must open the Insert a Log form and enter your preferred log parameters.
Opening the Insert a Log form¶
There are two ways to open the Insert a Log form.
Agents or Tags tab¶
- Open the Lightrun Sidebar in your VSCode IDE.
- Navigate to the Agents or Tags tab and select an agent or tag.
- Click the Add Action icon on the agent or tag.
-
Select Log in the menu that appears.
The Insert a Log form should appear similar to the following image.
Code line method¶
- 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 your remote app (where the agent is attached).
- Right-click to open the VSCode context menu.
- From the VSCode context menu, click Lightrun....
The VSCode Command Palette opens with a list of Lightrun plugin options.
- From the Command Palette, select Insert a Log
The Insert a Log form should appear similar to the following image.
Entering Log parameters¶
Complete the fields in the Insert a Log form, 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 the icon 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. |
LOG MESSAGE | The actual log string. Use expressions such as My variable is {var} , including method invocations such as: Method value: {myMethod() + 5} . |
LOG 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. |
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. |
LIFETIME | The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour. |
TARGET | Select your preferred action output taget. 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. |
Click Create to insert the dynamic log into your code.
Managing logs¶
Upon log creation:
- In the VSCode editor, a icon will appear next to the selected code line.
- A new log action will appear under the selected source (agent or tag) in the Lightrun sidebar.
You can disable, delete, or edit a log directly in your IDE.
To disable a Dynamic Log¶
- Hover your cursor over the relevant log in the Lightrun sidebar.
A toggle switch should appear.
- Click the toggle switch from blue (on) to grey (off).
- To resume logging, click the toggle back to blue.
To duplicate a Dynamic Log¶
- Hover your cursor over the relevant log in the Lightrun sidebar.
-
Right-click and select Duplicate.
-
Go to the selected destination and right-click and select Duplicate.
To delete a Dynamic Log¶
- Click the menu icon ... next to the relevant log in the Lightrun sidebar.
-
Select Delete from the menu that appears.
To edit a Dynamic Log configuration parameters¶
-
Click the menu icon ... next to the relevant log in the Lightrun sidebar.
-
Select Edit from the menu that appears to open the Edit a Log form.
The Edit a Log form should appear similar to the following image.
-
Edit your log configuration data in the Edit a Log form.