Issues to be aware of when using global logs in Python

Source: Internet
Author: User
After the soap WebService was developed using Uliweb, the Werkzeug log was lost when the Uliweb was started.

Normal log:

Copy the Code code as follows:

[INFO] * Loading debuggedapplication ...
[INFO] * Running on Http://localhost:8000/
[INFO] * Restarting with Reloader
[INFO] * Loading debuggedapplication ...

Log for exception:

Copy the Code code as follows:

[INFO] * Loading debuggedapplication ...
[INFO] * Loading debuggedapplication ...

In fact, Werkzeug related INFO and the following levels of the log are all not see, this is too weird, so decisively submitted issue

And after I created a new project and the app, and there was no log loss issue, I suspect that because I upgraded from Uliweb 0.1.3 to 0.1.4, my project was created using 0.1.3 and didn't notice the issue of the log before, but after getting the Limodou reply I denied This point.

    • Uliweb does not generate artifacts like Django manage.py when creating a project, such as settings.py and other configuration files and startup files, all of which are version-independent.

Think about it, the difference between my project and the newly created project is that Settings.ini has enriched some, then used the Pysimplelib, well, trace it from the source.

I looked at the Uliweb built-in Zerkzeug code, created the log here very clearly

uliweb/lib/werkzeug/serving.py

Copy the Code code as follows:

If not logging.root.handlers and _logger.level = = logging. NOTSET:
113 _logger.setlevel (Logging.info)
Handler = logging. Streamhandler ()
_logger.addhandler (handler) [code]

When Handler is already defined in the global logging.root or Werkzeug does not have a log level defined, Werkzeug sets its logger log level to info, and the location where the Werkzeug log is printed, happens to use the info level

[Code] [INFO] * Running on Http://localhost:8000/
[INFO] * Restarting with Reloader

That is, the Werkzeug log cannot be output because other logging handler have been defined

Results of grep pysimplelib

Copy the Code code as follows:

./client.py:33:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. WARNING)
./simplexml.py:27:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. WARNING)
./transport.py:30:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. WARNING)

All right, that's what this guy's doing. After commenting out the three lines of code, the Werkzeug log outputs normally

Said, this should not be regarded as uliweb problem, Pysimplesoap Library modification of the global design, it seems that should give it a issue is, this issue should be able to shut down.

Here's a workaround, added in Apps/settings.ini

Copy the Code code as follows:

[LOG. Loggers]
Werkzeug = {' Propagate ': 0, ' level ': ' Info ', ' format ': ' Format_simple '}

Of course, it is recommended that Limodou set the log level of the Zerkzeug in Default_settings.ini to info by default, because this is a very weird question, after all, the default log level in Werkzeug is info.

Well, look back, pysimplesoap because the global log level is overwritten, Werkzeug cannot enter a log below warning, so if we are developing an open Python library, we still have to hit the log in our own namespace, do not touch the global Logging settings, which can cause trouble for others.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.