Coder Social home page Coder Social logo

python-logging-example's Introduction

Python Logging Example

Often times when coding up a project I find myself injecting "print statements" all over the place to indicate status or messages important during development and debugging. Later, I might comment these statements out when "releasing" a script. While this works, it is a bit cumbersome and there is a better option available to the Python developer. Python logging.

This repository provides a very simple example of the same script with and without the logger.

  • example-print.py is a NETCONF based exmaple that looks up some information from a DevNet Sandbox and uses basic print statements to output to the console status messages.
  • example-logger.py is the same script, but uses Python logging to send informational and debug messages to a log file called mylog.log. Error messages will still be printed to the screen.
  • logger.conf is the Python logging configuration file
  • mylog.example is an example of what a log file might look like from this example and is included for reference.
    • If you run the example-logger.py a mylog.log file will be created.
  • requirements.txt is a Python requirements file that includes the needed libraries to run the example scripts.

For reference on the Python Logging features, see the Logging HOWTO from Python.org.

Also, checkout the blog Avoiding Silent Automation by Joe Clarke, Cisco Distinguished Engineer and fellow automation engineer I work with in Learning at Cisco. His blog is what introduced me to logging in a way that made me want to really dive in and start using it.

python-logging-example's People

Contributors

hpreston avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.