Dynamic log_filename with dates in setup.py

Hi, I am trying to distribute my Panda3D app and I want to have the panda log output to a logfile filename based on the time the user uses the app.
So something like


So the log would log crashes and would not be overwritten.

    name='my app',
        'build_apps': {
            'console_apps': {'My App': 'main.py'},
            'log_filename': '$USER_APPDATA/Panda3D/log/output1.9.log',
            'log_append': False,

Thanks for the help!

I think instead of adding it in the seup.py, in the main.py you can create the file.

For example:

log_file = open("log_file.log", "wt")

It seems this isn’t supported by pandas setup tools at the moment. Though you can rather easily redirect pandas output to a log file. Here’s a sample that should match your desired style and location. Just put that somewhere before you initialize the engine.

    from direct.showbase.ShowBase import ShowBase
    from panda3d.core import MultiplexStream, Notify, Filename
    import sys, os, string
    from datetime import datetime

    # create log path
    logPath = os.path.join(

    # part taken from the setup tools code
    t = string.Template(logPath)
    if sys.platform.startswith('win'):
        logPath = t.substitute(HOME='~', USER_APPDATA='~/AppData/Local')
    elif sys.platform.startswith('macosx'):
        logPath = t.substitute(HOME='~', USER_APPDATA='~/Documents')
        logPath = t.substitute(HOME='~', USER_APPDATA='~/.local/share')

    # make sure ~ and other special path elements are converted to a full path
    logPath = os.path.expanduser(logPath)

    # create logfile full name
    logfile = os.path.join(

    # chec if the path exists
    if not os.path.exists(logPath):

    # Redirect pandas logging (notify) to our own stream
    nout = MultiplexStream()
    Notify.ptr().setOstreamPtr(nout, 0)

    # make sure our log file doesn't exist yet
    if os.path.exists(logfile):

    # set our otuput stream to write to our log file

    # Run your app
    app = ShowBase()
1 Like

This is not a bad idea. We could without much effort support strftime format in the filename.

Please file a feature request on GitHub, thanks!

This is implemented in Panda3D 1.10.9, see:

1 Like