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:

from datetime import datetime, timedelta
​
import dstack.controls as ctrl
import dstack as ds
import plotly.graph_objects as go
import pandas_datareader.data as web
​
​
def symbols_handler(symbols: ctrl.ComboBox):
print("Calling symbols_handler")
symbols.data = ['FB', 'AMZN', 'AAPL', 'NFLX', 'GOOG']
​
​
def get_chart(symbols: ctrl.ComboBox):
print("Calling get_chart")
start = datetime.today() - timedelta(days=30)
end = datetime.today()
df = web.DataReader(symbols.value(), 'yahoo', start, end)
fig = go.Figure(
data=[go.Candlestick(x=df.index, open=df['Open'], high=df['High'], low=df['Low'], close=df['Close'])])
return fig
​
​
app = ds.app(get_chart, symbols=ctrl.ComboBox(handler=symbols_handler, require_apply=True))
​
result = ds.push('faang_with_logs', app)
print(result.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:

​