Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

You're reading from  Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781783551590
Pages 200 pages
Edition 1st Edition
Languages
Author (1):
Dan Nixon Dan Nixon
Profile icon Dan Nixon

Writing log files


The next technique we will look at is having our application output a log file. This allows us to get a better understanding of what was happening at the time an application failed, which can provide key information into finding the cause of the failure, especially when the failure is being reported by a user of your application.

We will add some logging statements to the Calculator.py and Operation.py files. To do this, we must first add the import for the logging module (https://docs.python.org/2/library/logging.html) to the start of each python file, which is simply:

import logging

In the Operation.py file, we will add two logging calls in the evaluate function, as shown in the following code:

def evaluate(self, a, b):
    logging.getLogger(__name__).info("Evaluating operation: %s" % (self._operation))
    logging.getLogger(__name__).debug("RHS: %f, LHS: %f" % (a, b))

This will output two logging statements: one at the debug level and one at the information level. There are...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}