I have a simple a Kivy interface that also uses the terminal.
Example code:
import kivy
kivy.require('1.0.6')
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text = 'Hello')
MyApp().run()
The problem is that whenever I start the script I get this:
[INFO ] [Logger ] Record log in C:\Users\Simon\.kivy\logs\kivy_18-05-12_37.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.5.13467 Compatibility Profile Context 21.19.414.1280'>
[INFO ] [GL ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO ] [GL ] OpenGL renderer <b'AMD Radeon R7 Graphics'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
I have found that this is Kivy's automatic debugging messages. How do I prevent them (or at least hide so that I can use the terminal)?
As shown in the docs, you should only do the following:
import os
os.environ["KIVY_NO_CONSOLELOG"] = "1"
import kivy
...
Now you can set what kind of logs you want to see by setting Config
.
You can choose one of trace
, debug
, info
, warning
, error
or critical
from kivy.config import Config
# your code ...
if __name__ == '__main__':
# path of the log directory
Config.set('kivy', 'log_dir', 'your_chosen_log_dir_path')
# filename of the log file
Config.set('kivy', 'log_name', "anything_you_want_%y-%m-%d_%_.log")
# Keep log_maxfiles recent logfiles while purging the log directory. Set ‘log_maxfiles’ to -1 to disable logfile purging (eg keep all logfiles).
Config.set('kivy', 'log_maxfiles', 1000)
# minimum log level which is what you need to not see kivy's default info logs
Config.set('kivy', 'log_level', 'error')
# apply all these changes
Config.write()
Keep in mind that setting the config variables and running the program does not immediately stop default debug messages. You will still see them on the first run. It is because Kivy sets the config variables on the first run, then applies it from the following runs. So, you need to run it twice to see the effects take place.
Setting os.environ["KIVY_NO_CONSOLELOG"] = "1"
does remove debug messages, but it also not allows you to see error and critical messages. So setting it would not be a wise option if you want to see errors and tracebacks.
Sources:
Kivy's official explanation on all config settings.
Kivy's official explanation on Logger object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With