Is pn.state.log supposed to go to the admin panel?

I am trying to get some application-level logs to show up in my /admin app.

I have tried pn.state.log(…) and logging.getLogger(“panel”) – neither of which seems to be showing up in the admin logs

The docs seem to imply pn.state.log should work View application logs — Panel v1.4.4

but when I look at the image on the output, the demo message ("clustering… ") isn’t shown. So maybe it doesn’t work?

Nevermind – seems to work now that I updated my virtual environment!

can you explain me how you did that

Sure! here’s a sample program:

import panel as pn
import param
import textwrap

class MyApp(pn.viewable.Viewer):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def log_count(self, clicks):
        pn.state.log(f"Button clicked {clicks} times", level="error")
    
    def button(self):
        click_me =  pn.widgets.Button(name="Push button!", button_type="primary")
        pn.bind(self.log_count, click_me.param.clicks, watch=True)
        return click_me

    def message(self):
        return pn.pane.Markdown(textwrap.dedent(
        """
        # Logging example

        When you push the button, an error message will be logged.
        Click the button a few times, then
        [check the admin panel](/admin) - look for app = `panel.state`

        If the admin panel is broken, make sure you started
        this file with `panel serve --admin` option.
        """
        ))

    def __panel__(self):
        return pn.Column(self.message, self.button)


MyApp().servable()

Just copy the source above to a file (let’s say “app.py”, then run panel serve --admin app.py

1 Like