When I import kivy
in python:
>>> import kivy
The following three debug lines get printed:
[INFO ] [Logger ] Record Log in C:\Users\usrname\.kivy\logs\kivy_18-04-07_50.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
I know this is rather intended than an error, but I'd like to suppress this output. I have read the file kivy\__init__.py
and figured out that the lines get printed when following line is executed:
from kivy.compat import PY2
So I have read kivy\compat.py
too, which isn't even a big file (102 lines), but I still can't see why the debug lines get printed.
I've executed every single line (including docstrings and comments) of the file in the python console and couldn't reproduce it.
Can somebody explain this to me? I assume that this is something internal and is only possible because I installed it with pip but actually I have no clue what's going on here.
The output is generated by the kivy.logger
module, which simply uses the standard Python logger
module.
The module adds a logger to output to the console, unless the KIVY_NO_CONSOLELOG
environment variable has been set:
if 'KIVY_NO_CONSOLELOG' not in os.environ:
# ...
formatter = ColoredFormatter(color_fmt, use_color=use_color)
console = ConsoleHandler()
console.setFormatter(formatter)
Logger.addHandler(console)
From that point on, logged messages are printed out to your console.
It is not the kivy.compat
module that triggers all this; when importing a module inside a package, Python will always make sure that the package itself is loaded first. Thus import kivy.compat
will trigger an import of kivy
itself if not already loaded.
It is kivy/__init__.py
that outputs the first log message:
if RELEASE:
Logger.info('Kivy: v%s' % (__version__))
but the kivy.logger.FileHandler
object that is also configured (unless KIVY_NO_FILELOG
is set in the environment) runs extra code when first used and inserts Logger.info('Logger: Record log in %s' % filename)
before the Kivy: v<version>
message is handled. Finally, kivy/__init__.py
executes Logger.info('Python: v{}'.format(sys.version))
to output the Python version info.