Hi there
I am using logging package in my server code and I have statements like:
import logging
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
logging.info('My Info Log')
I see these logs don’t appear in App’s Logs.
Is there a way to have these logs in my App’s Logs? Or I need to revert to the good plain old print()?
Logging package is useful and has most of the things you need already built in.
1 Like
As a practical question, what would you add that is not already in Anvil’s logs?
Hi
well at least
- leveraging a built-in package designed to this purpose, with levels management, format management and every facility you could think of
- avoid refactoring existing codebases to “downgrade” logging management from using the builtin package to cusotm print() statements
- keep a single codebase that can run consistently between Anvil’s server environment and Uplinked servers, where built-in logging package is a best practice
I admit this is not indispensable but would be nice.
So, everyone is logging with print statements here?
2 Likes
I haven’t tried this, but what happens if you define a handler that directs to stdout and add that to your logger? Something like:
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
All great points. Thanks for making me think! 
2 Likes
Next up: add a handler that also logs to a data table…
I feel an update to my orm coming shortly.
2 Likes
Ouch that was a big miss!
Thanks Owen!
I didn’t event think of that, you’re absolutely right and now that I read it I wonder how didn’t that come up to my mind myself…
This is why this forum is so helpful, I was missing a point as big as a mountain because I was looking at my feet…
1 Like
Not sure who Paul might be, but you’re welcome. Glad it helped!
1 Like
Ahahaha my aplogies
, my messed mind mixed your content with “p.colbert” !!
Thanks Owen and again sorry for that. I fix the attribution immediately. 
1 Like
Would you mind marking this one as solved?
To wrap it up
Here you can find ‘logging’ usable within Anvil.
https://anvil-extras.readthedocs.io/en/latest/guides/modules/logging.html
Once it is added to dependencies, you could do
from anvil_extras.logging import Logger, DEBUG
import sys
log = Logger(
name="user",
level=DEBUG,
stream=sys.stdout,
format="{datetime:%Y-%m-%d %H:%M:%S} | {name} | {level} | {msg}",
)
log.debug("Debug message")
log.info("Info message")
log.error("Something went wrong")
In name="user", I set the name of the Form/Module
So the output is visible on the Running App Console and looks like
2025-10-09 18:08:34 | EventEditorForm | INFO | Hello from foo
2025-10-09 18:08:34 | DashboardForm | DEBUG | Debug message
2025-10-09 18:08:34 | DashboardForm | INFO | Info message
2025-10-09 18:08:34 | DashboardForm | ERROR | Something went wrong
2025-10-09 18:08:34 | DashboardForm | INFO | Hello from foo
2025-10-09 18:08:34 | DashboardForm | INFO | Hello from a
2025-10-09 18:08:34 | DashboardForm | DEBUG | This goes to stdout

Feel free to improve.
2 Likes