#Can't see log outputs from embedded within functions.

27 messages · Page 1 of 1 (latest)

knotty oar
#

Is it possible to view 'print' statement output which are embedded inside of a function of the backend views files? No matter what I try i can't see them in the runserver terminal console.

DEBUG = True
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
        'file': {
            'class': 'logging.FileHandler',
            'filename': 'debug.log',
            'formatter': 'verbose',
        },
    },
    'formatters': {
        'verbose': {
            'format': '{asctime} {levelname} {name} {message}',
            'style': '{',
        },
    },
    'root': {
        'handlers': ['file'],
        'level': 'WARNING',  
    },
    'loggers': {
        'django': {
            'handlers': ['console', 'file'],
            'level': 'ERROR',
            'propagate': False, 
        },
        'app_backend': {
            'handlers': ['console', 'file'],
            'level': 'DEBUG',
            'propagate': False, 
        },
    },
}
worn heath
#

I'd start by changing WARNING and ERROR to DEBUG

knotty oar
# worn heath I'd start by changing `WARNING` and `ERROR` to `DEBUG`

Thanks, I changed to DEBUG again just to make sure.
When I start the backend with runserver, there is a long list of messages from the initialization and importing of the startup which is the normal behavior. I've seen.
But it didn't provide me the answer to the problem

Maybe there isn't a way to print function embedded log statements to the server console when the function is called.

I've tried every method I have come across, with no success.

worn heath
#

if your code is on github, and if it's super-easy for me to run it and see the problem you're describing, post the URL

knotty oar
worn heath
#

dunno what log or print statements that are inside of a function means; where else would they be?

knotty oar
# worn heath dunno what `log or print statements that are inside of a function` means; where ...

oh! I typically work with python scripts running headless (no frontend) . And this is my first project using a stack.

ok, this is what I call the root level of a script.

import logging

logger = logging.getLogger('anothen_backend')
logger.debug("This is a test debug message")
logger.info("This is a test info message")
logger.warning("This is a test warning message")
logger.error("This is a test error message")

when I start the runserver, I can see then in the console.

Performing system checks...

2024-07-15 09:32:42,200 DEBUG anothen_backend This is a test debug message
2024-07-15 09:32:42,200 INFO anothen_backend This is a test info message
2024-07-15 09:32:42,200 WARNING anothen_backend This is a test warning message
2024-07-15 09:32:42,200 ERROR anothen_backend This is a test error message
System check identified no issues (0 silenced).
July 15, 2024 - 09:32:42
#

however this,

def options_chain(symbol):
    logger.debug("calling options chain")
    

does not ever show in the console.

worn heath
#

it must have something to do with how the function is called

#

and which logger it's using

knotty oar
#

you can see a message like that printed to the console?

worn heath
#

!e


logger = logging.getLogger("anothen_backend")
logger.setLevel(logging.DEBUG)
logger.debug("This is a test debug message")
logger.info("This is a test info message")
logger.warning("This is a test warning message")
logger.error("This is a test error message")


def options_chain():
    logger.debug("calling options chain")


options_chain()
#

ugh

#

well that prints this when I run it ```
2024-07-15T14:52:17+0000 DEBUG /var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/bobaleaux.py <module> This is a test debug message
2024-07-15T14:52:17+0000 INFO /var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/bobaleaux.py <module> This is a test info message
2024-07-15T14:52:17+0000 WARNING /var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/bobaleaux.py <module> This is a test warning message
2024-07-15T14:52:17+0000 ERROR /var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/bobaleaux.py <module> This is a test error message
2024-07-15T14:52:17+0000 DEBUG /var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/bobaleaux.py options_chain calling options chain

#

so yes, it works fine

#

there's nothing at all special about logging calls that are made inside a function, as opposed to top level.

#

your problem is elsewhere.

knotty oar
#

shoot! I just can't figure this out.

worn heath
#

either it's not the same logger, or else something has modified the logging setup after your top-level code has run.

#

use the logging-tree thing I linked to above. It's helped me a bunch of times.

knotty oar
#

thanks, I'm going to try it. I have to figure it out because honestly, I've been fighting this for almost 2 weeks (less 4 days without power from the hurricane)

worn heath
#

heh, logging-tree will take you an hour or so at most. Be patient; it's not super easy; you have to learn to interpret its output.

#

But I'll give it, oh, say, an 80% chance of solving your problem.

knotty oar
worn heath
#

pff

#

if logging-tree solves your problem and grows back your hair, I expect you to buy me a virtual beer