Logging

Learn how to log events of the application.

When developing an application, sometimes it is helpful to log application events and browse them as the application is being used. dstack offers a simple way to log application events and access them from the interface.

The easiest way of logging application events is by printing them into stdout (e.g. using print()). Here's an example:

import dstack as ds
import plotly.express as px
​
app = ds.app() # Π‘reate an instance of the application
​
​
# An utility function that loads the data
def get_data():
return px.data.stocks()
​
​
# A drop-down control that shows stock symbols
stock = app.select(items=get_data().columns[1:].tolist())
​
​
# A handler that updates the plot based on the selected stock
def output_handler(self, stock):
print("Calling output_handler") # Log a message
symbol = stock.value() # the selected stock
# a plotly line chart where the X axis is date and Y is the stock's price
self.data = px.line(get_data(), x='date', y=symbol)
​
​
# A plotly chart output
app.output(handler=output_handler, depends=[stock], require_apply=True)
​
# Deploy the application with the name "stocks_logs" and print its URL
url = app.deploy("stocks_logs")
print(url)

Now, if we open the application, and click Apply, we'll see the Logs tab at the bottom of the application. When expanded, it shows the events printed into stdout from the application:

​