Giter VIP home page Giter VIP logo

printbetter's Introduction

PrintBetter


Description

I created this module because I had had enough of writing and rewriting the same piece of code every time I needed to print something in Python ๐Ÿ’ข. I wanted two things:

  • To be able to keep what I had printed on the console after I having closed it -> log file ๐Ÿ“
  • To see the time when the print was executed -> print prefix โŒš๏ธ

In addition to all that I added a simple and nice feature which is multiple print "types":

  • Information [INFO] -> the basic one, replaces the old print
  • Debugging [DEBUG] -> when you print something just to see a variable content, Oh yeah you need this!
  • Warning [WARNING] -> when you need to show a warning
  • Error [ERROR] -> when you need to display that an error occurred, so we do not need to use raise which prints a massive and ugly block of red code inside your clean and sweet console

It also had to be fully customizable because I hate it when I am forced to use some part of a module that I do not really like ๐Ÿ’ฏ.

Feel free to make a pull request if you have any upgrade idea.

That is it! A new way to print things in python! โœ…

Features

Use PrintBetter to have a nice prefix before printing anything on the console output. It also creates a clean log file where you can find anything that you have printed during the program execution. ๐Ÿ˜Š

โšก๏ธ Quick Start

Installation is really simple:

pip install printbetter

Usage

You need to initialize the module in order to have the log file set up properly:

import printbetter as pb

pb.init()  # Initializes the log file and the printing format

pb.info("Everything is set up properly!")

โœ๏ธ Default example

import printbetter as pb

pb.init()

pb.info("information")
pb.debug("variable debug")
pb.warn("warning")
pb.err("error")

Imports

This module uses 2 other modules that it imports:

  • time
  • os

(no need to install anything, the 2 modules are in the Standard Python Module Library)

Documentation

The full documentation ๐Ÿ“„ below comes directly from the code's docstring. It makes the documentation readable directly from any compatible IDE or text editors. I recommend using Visual Studio Code.

Initialization init()

You should call this function before logging anything in your program. Initializes the module: creates the log file in the right path and defines the logging format. If needed all the different parameters are here to set each variable without using the proper function.

Definition

def init(print_out=True, log_file=True, log_path="logs/logfile_%d-%m-%y_%H.%M.%S.log",
         log_format='[%(asctime)s] %(levelname)s : %(message)s', log_date_fmt='%d/%m/%y %H:%M:%S',
         print_prefix_format="[%d/%m/%y %H:%M:%S]"):

Information info(text)

Logs an information out.

Log result

[09/04/20 11:14:40] INFO : information

Debug debug(debug_info)

Logs a debugging information out.

Log result

[09/04/20 11:14:40] DEBUG : variable debug

Warning warn(warning)

Logs a warning out.

Log result

[09/04/20 11:14:40] WARNING : warning

Error err(error)

Logs an error out.

Log result

[09/04/20 11:14:40] ERROR : error

Disable the log file feature disable_LOG_FILE()

Disables the creation of the log file and the logging into an existing log file for the next printbetter functions.

Example

pb.disable_LOG_FILE()  # Disables the log file
pb.init()  # Initializes the printing format
pb.info("Everything is set up properly!")  # Formats the text and prints it on the console only

Enable the log file feature enable_LOG_FILE()

Re-enables the creation of the log file and the logging into the log file for next printbetter functions.

Example

pb.init()  # Initializes the printing format
pb.info("Everything is set up properly!")  # Printed on the console and written in the log file
pb.disable_LOG_FILE()  # Disables the log file
pb.info("Just print this!")  # Only printed on the console
pb.enable_LOG_FILE()  # Enables the logging into the log file
pb.info("Everything is set up properly!")  # Printed on the console and written in the log file

Disable the print feature disable_PRINT_OUT()

Disables the printing on the console for next printbetter functions.

Example

pb.disable_PRINT_OUT()  # Disables the console printing
pb.init()  # Initialization
pb.info("Everything is set up properly!")  # Formats the text and writes it in the log file only

Enable the print feature enable_PRINT_OUT()

Re-enables the console printing for next printbetter functions.

Example

pb.init()  # Initialization
pb.info("Everything is set up properly!")  # Printed on the console and written in the log file
pb.disable_PRINT_OUT()  # Disables the console printing
pb.info("Just log this!")  # Only written in the log file
pb.enable_PRINT_OUT()  # Enables the console printing
pb.info("Everything is set up properly!")  # Printed on the console and written in the log file

This module was developed by Lucas Jung alias @Gruvw. Contact me directly on GitHub or via E-Mail at: [email protected]

printbetter's People

Contributors

gruvw avatar

Watchers

 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.