Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Logging objects


The log in any software is useful for many aspects, one of them being exception handling. Kivy is always logging information about its performance. It creates a log file of every running of our app. Every programmer knows how helpful logging is for software engineering. In this recipe, we want to show information of our app in that log.

How to do it…

We will use a Python file with the MyW() usual class where we will raise an error and display it in the Kivy log. To complete the recipe, follow these steps:

  1. Import the usual kivy package.

  2. Import the Logger packages.

  3. Define the MyW() class.

  4. Trigger an info log.

  5. Trigger a debug log.

  6. Perform an exception.

  7. Trigger an exception log:

    import kivy
    kivy.require('1.9.0')
    from kivy.app import App
    from kivy.uix.widget import Widget
    from kivy.logger import Logger
    
    class MyW(Widget):
        Logger.info('MyW: This is an info message.')
        Logger.debug('MyW: This is a debug message.')
        try:
            raise Exception('exception')
        except Exception:...