• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Devpy is a set of tools to ease Python development, providing automatic logging

DEVPY

Devpy is a set of tools to ease Python development.

Install

pip install devpy

Quick demo

Devpy provides a quick dev setup for logging that you can replace later by a more robust solution:

import devpy.develop as log

log.info('This is an info')
log.warning('This is a warning')
log.error('This is an error')
log.critical('This is a critical error')

log.info('Now let me crash the program. This stack trace is automatically in the log file:')

import codecs

codecs.open('/thisdoesnotexist')

This gives:

screenshot.png

Autolog

Setting up proper logging is tedious, so you may want to do it later, but you wish you could get basic logging right away:

import devpy

# Get a logger that automatically logs to console and a rotating file
# The rotating file is setup in the temp directory of your system, in
# a subdir named after your script name.
# Logs are colored in the console according to their level.
# The file path is printed at the beginning of the program.

log = devpy.autolog() # log is a regular stdlib logger object

# start logging:

log.info('Yes')

Once you have time to setup logging seriously, you can just replace the autolog with a regular custom Python logger, and all your logs will still work.

Setting the environment variable DEVPY_LOG_LEVEL to an integer or a level name (debug, info, error, warning, critical...) will set the autolog log to it.

Setting the environment variable DEVPY_COLOR_LOG to 0 disables log highlighting.

autolog parameters:

  • level (default=-1): the general log level
  • name (defaul=name of the root module): the name of the log file
  • path (default=OS temp dir + name): path to the log file
  • log_on_crash (default=True): add a hook to log the stack trace in case of a crash
  • log_filename (default=True): log log file path at the program start
  • color_log (default=True): add colors to the log

Stacktrace helper

Format the stack trace so that:

  • it separates the various logicial blocs
  • it emphasizes the lines of your program and not the stdlib
  • lines of your program are syntax highlighted

Just do:

import devpy
devpy.color_traceback()

All helpers at once

Two ways:

import devpy
log = devpy.dev_mode()  # can set color_traceback=True, autolog=True

# or just
# import devpy.develop as log
# for a one liner to activate it all

More Repositories

1

django-quicky

A collection of toys to skip the forplay with Django and go straight to the point: url and view decorators.
Python
371
star
2

Django--an-app-at-a-time

A heavily commented Django project dedicated to teaching the framework or refresh one's memory.
Python
277
star
3

VizHash.js

A javascript implementation of visual hash using html5 canvas
JavaScript
51
star
4

minibelt

One-file utility module filled with helper functions for day to day Python programming
Python
43
star
5

Bat-belt

A collection of gagdets make Python even more powerful
Python
33
star
6

codes-des-articles

Codes des articles du blog sam et max
Python
17
star
7

miroir-du-blog

Miroir du blog et des tweet de sam et max pour consultation hors ligne
HTML
14
star
8

LiveCss.js

Automatically reload newly changed css files without reloading the page
JavaScript
12
star
9

multiboards

JavaScript
9
star
10

jQuery-Visual-Password

A jquery plugin to create visual hash of the value of a password field as it is typed
Shell
9
star
11

templite

A light-weight, fully functional, general purpose Python templating engine that fits in one single file
Python
7
star
12

requests-twisted

Twisted adapter for the requests library
Python
7
star
13

allthatcounts

Countdown + chrono + game clocks + counters in one a page pure JS app for mobile and desktop, with an offline mode
JavaScript
6
star
14

sm_lib

Ce module proclame la bonne parole de sieurs Sam et Max.
Python
5
star
15

crack_the_safe

Un jeu temporaire pour le blog sam et max
Python
1
star
16

manga-reader.js

A bookmarklet that ease Manga reading on sites like mangareader.net, mangafox.me, mangahere.com, etc.
JavaScript
1
star