Bring color and formatting to your logs

colorful, colorization, log, logger, logging, logging-library, logging-server, pretty, pretty-print, prettytable, python
pip install plogs==0.1.5


plogs — Pretty Logs

Project Goals

In the beginning, the goal of Pretty Logs was to create a colorful logging system designed for scalable projects. Later, my vision for Pretty Logs widened in scope to also include useful debugging tools that are found in JavaScript and aren't that readily available in Python.

In the future, we anticipate better control to configure logging settings and a debugging log level where debug tools can only print to.


You can install Pretty Logs via pip. pypi link

$ pip install --upgrade plogs


Importing Pretty Logs into your project is quite simple. All that's required is to import plogs and instantiate an instance of Logger.

from plogs import get_logger
logging = get_logger()

It's recommend to do the following steps inside a file at the root level of your project so Pretty Logs can be referenced throughout the entire application.

Log with Colors

Pretty Logs' main feature is color coding different logging levels and statuses. The default logging levels are set mapped to:

Log Level Color gray
logging.status bold
logging.success green
logging.warning orange
logging.error red
logging.critical red highlights

Log to a File

Pretty Logs can write colored logs to files. This is done through Pretty Logs' config function.

from plogs import get_logger

logging = get_logger()
logging.config(to_file=True)'this is will be written to a file')

By default, files are written to /var/log/plogs/plog_01.log. /var/log/ is chosen as the default directory because it is commonly used on unix based machines and in docker images services.

If you are looking to use another filename and location, it can simply be edited like such:

logging.config(to_file=True, file_location='your/filepath/here/', filename='new_file.log')

Note: It's recommended to view colored logs with the less terminal command - if less doesn't work be default, less -r is worth trying. Also, Pretty Logs was not designed to show colored files in Vim, Atom, Sublime, and other popular text editors.

Formating Logs

Pretty Logs allows for a lot of customization. Customizing logs is done by editing the logging config and supplying Pretty Logs with a formatted string.

The following are all the configurable variables:

Variable Type Format Keyword Description
pretty bool N/A Setting to True will add color to logs, False will un-color logs
show_levels bool {level} Setting to True will show logging level in formatted log, False show no logging level
show_time bool {time} Setting to True will show time in formatted log, False doesn't show time
to_file bool N/A Setting to True writes logs to file_location, False writes to standard output
file_location str {file_location} Default file_location is /var/log/plogs/, otherwise a file location of your choice
filename str {filename} Default log file is plog_01.log, otherwise a filename of your choice
N\A N/A {msg} Shows the log message in formatted log

An example of a formatted logs would be like such:

from plogs import get_logger

logging = get_logger()

# configure plogs to allow logging level and date/time
logging.config(show_levels=True, show_time=True)

# config logs with the `{level}` keyword to show the logging level,
# `{time}` to show the date & time of when the log was written
# and `{msg} to show the logging message
logging.format('[{level}] - {time} - {msg}')

# finally write logs
logging.status('Show me the logs')'We got some info')

# Output:
# [STATUS] - 2018-12-11 11:56:05 - Show me the logs
# [INFO] - 2018-12-11 11:56:09 - We got some info

NOTE: In order to format Pretty Logs you must put the variable you want written inside {} - ie like so: {filename}, {file_location}, {levels}, etc. These values will be substituted for the variable they represent

How can I Contribute?

If you are looking to contribute, you can check out you the how to contribute doc