question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

logging.debug() doesn't seem to make it to the logs

See original GitHub issue

info(), warning(), and error() all show up in Application Insights, but debug() does not. Not sure if this is a worker issue or an Application Insights issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shabbyrobecommented, May 12, 2020

This is still an issue as far as I can see, I just lost quite a bit of time trying to track down why logging.debug() never makes it to the console using azure-functions-core-tools 3.0.2245. The snippet posted earlier does not help; core tools shows its own debug messages but the logging.debug() calls from the python worker continue to be swallowed.

If I change this line to DEBUG, I see the output I expect in the console: https://github.com/Azure/azure-functions-python-worker/blob/dev/azure_functions_worker/dispatcher.py#L122

I tried to follow the suggestion to pass --log-level=DEBUG to the worker, but this log level is not included in the argparse setup: https://github.com/Azure/azure-functions-python-worker/blob/dev/azure_functions_worker/main.py#L19

Furthermore, azure-functions-core-tools does not seem to provide a functioning mechanism to actually pass this argument, but my C# is a bit rusty, I have no development environment to use to debug that project on this work machine, and the way the code comes together to construct the config for Microsoft.Azure.WebJobs is a bit inscrutable and stringly-typed, so I couldn’t quite follow it without investing significantly more time.

I did manage to discover that I can pass args through to the worker using --language-worker, but it’s prepend only and shoves the new arguments before the worker.py file, so it’s close to useless without a shim script:

# exec-fa.py
import subprocess
import sys
sys.exit(subprocess.call(["python", *sys.argv[1:], "--log-level=TRACE"]))
$ func start --python  --language-worker ./exec-fa.py

So my shim script “works”, in the sense that it starts the worker with the extra arguments appended, but the logging.debug() calls are still swallowed unless I manually hack dispatcher.py:122. This will do for me for now, but I can’t share this workflow with the other developers on my team, it’s unreasonable to expect them to be willing to do this.

I don’t really know what to suggest here, but unless debug logging is explicitly not supported (if so, it should be documented prominently), it really seems to me like this issue should still be open.

2reactions
maiqbal11commented, Feb 12, 2019

@elprans, we should be fine to keep the system logs at the informational level. Those are already being sent to the table where keep our debugging information.

As for the original issue noted here, the desired behavior can be achieved with a combination of two steps:

  1. Setting the root logger in user code to use the debug level (it is set to to info by default).
  2. Configuring the host.json to log Debug messages:
{
  "version":  "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Debug"
    }
  } 
}

With these changes, the logs should be visible on both the console as well as Application Insights. @asavaritayal, we can make note of this in our development wiki. Changing the logging settings currently would require re-deployment but we might be able to introduce some app settings to achieve this if that’s the route we want to go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python logging not outputting anything - Stack Overflow
debug ("Some string") , I get no output to the console, even though this page in the docs says that logging.debug should have...
Read more >
Logging HOWTO — Python 3.11.1 documentation
logging.info() (or logging.debug() for very detailed output for diagnostic ... The INFO message doesn't appear because the default level is WARNING .
Read more >
Debug Logs - Salesforce Help
Use debug logs to track events that occur in your org. Debug logs are generated when you have active user-based trace flags, when...
Read more >
Python Logging: A Stroll Through the Source Code
Because the logger has level DEBUG , and the message carries a higher INFO level, it gets the go-ahead to move on. Internally,...
Read more >
console.log() doesn't seem to work in Generic JavaScript View ...
Hi, i'm trying to debug codes, but i have a hard time finding errors because console.log doesn't create any output.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found