Skip to main content

Prettify-Logging is a wrapper tool that colors the stream formatting of the logging module.

Project description

Prettify-Logging

Prettify-Logging is a wrapper tool that colors the stream formatting of the logging module.

Installation

Prettify-Logging is a python package which can be found on Python Package Index (PyPi). Run the following command to install:

pip install prettify-logging

Import Prettify-Logging Into Your Projects

from PrettifyLogging.prettify_logging import PrettifyLogging

Usage

Making changes from the default configuration of PrettifyLogging must be completed before calling PrettifyLogging().configure(). PrettifyLogging config options:

key: name = (str) [Required]. Name of the log file to be created. Example: 'my_log_file.log'

key: level = (str) Log level to log records. Default is 'error'. Example: 'debug'

key: set_utc = (bool) Set time entry in log to UTC. Default is True.

key: default_format = (str) Default log record formatting. Default is:
      [%(asctime)s] - %(name)s - %(levelname)s - (%(module)s, %(funcName)s, %(lineno)d): %(message)s
      
key: stream_format = (str) Log record formatting. Default is default_format. Example:
      %(asctime)s - %(name)s - %(levelname)s - %(message)s
      
key: file_format = (str) Log record formatting. Default is default_format. Example:
      %(asctime)s - %(name)s - %(levelname)s - %(message)s

key: debug_display  = (str, tuple): Debug stream formatting. Default is "bright-black".

key: info_display  = (str, tuple): Info stream formatting. Default is "blue".

key: warning_display = (str, tuple): Warning stream formatting. Default is "yellow".

key: error_display  = (str, tuple): Error stream formatting. Default is "bright-red".

key: critical_display  = (str, tuple): Critical stream formatting. Default is ('red', 'invert').

Setting the configuration options on PrettifyLogging() can be made by passing the config as key=value to the class, using a dictionary to define the key values, or by using dot notation to define particular values.

The name (file name for the log file) must be set before calling PrettifyLogging().configure(). Example:

log = PrettifyLogging(name="my_log_file.log").configure()
# or
logger = PrettifyLogging()
logger.name = "my_log_file.log"
logger.configure()

When making display changes (debug_display, info_display, warning_display, error_display, or critical_display keys) the value can be either a string or tuple. If the value is a string, then the value string must define a color type. If the value is a tuple, the tuple must include a string that defines a color type. To view the coloring options, please see Color-Fi or you can print to console by running the following:

logging = PrettifyLogging()
logging.display_key_options()

Coloring examples can be found in the below examples.

Using Key=Value to Define Config Settings and View Default Stream Output:

logging = PrettifyLogging(name="test.log", level="debug")
logging.configure()
logging.display_test()

Output as png:
message Sample

Using Dictionary To Define Config Settings:

default = '%(asctime)s - %(name)s - %(levelname)s - %(funcName)s: %(message)s'
config = {
    'name': 'test.log',
    'level': 'debug',
    'set_utc': False,
    'default_format': default,
    'stream_format': default,
    'file_format': default,
    'debug_display': 'blue',
    'info_display': ('cyan', 'bold'),
    'warning_display': ('invert', 'bright-magenta'),
    'error_display': 'yellow',
    'critical_display': ('underline', 'bright-green', 'background')
}
logging = PrettifyLogging(**config)
logging.configure()
logging.display_test()

Output as png:
message Sample

Using Dot Notation to Define Settings:

logging = PrettifyLogging()
logging.name = "test.log"
logging.level = "debug"
logging.debug_display = ('magenta', 'bold')
logging.info_display = 'cyan'
logging.warning_display = ('italic', 'bright-green', 'foreground')
logging.error_display = ('blue', 'invert')
logging.critical_display = ('yellow', 'bold', 'background')
logging.stream_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.configure()
logging.display_test()

Output as png:
message Sample

Making Log Entries:

log = PrettifyLogging(name="test.log", level="info").configure()
log.info('I am logging this...')
# or
logger = PrettifyLogging(name="test.log", level="debug")
log = logger.configure()
log.debug('I am also logging this...')
# or
logger = PrettifyLogging(name="test.log")
logger.configure()
logger.log.error('This also is getting logged...')

Print to Console in Color Without Logging:

logger = PrettifyLogging()
logger.print_message('Message 1', 'green')
logger.print_message('Message 2', 'red', _format='bold')
logger.print_message('Message 3', 'yellow', 'background', 'underline')

Output as png:
message Sample

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Prettify-Logging-1.0.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Prettify_Logging-1.0.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file Prettify-Logging-1.0.2.tar.gz.

File metadata

  • Download URL: Prettify-Logging-1.0.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for Prettify-Logging-1.0.2.tar.gz
Algorithm Hash digest
SHA256 784801fdf3503c08a0363388cc5a22437b8c4b3d13bc6871c164fec7ffba91f9
MD5 b16129304f6146bfe8a9a68d58e16477
BLAKE2b-256 ea7a9437f39e862e9366bce87068b7607366ba6ee5be0f604ab19f58937e61c9

See more details on using hashes here.

File details

Details for the file Prettify_Logging-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for Prettify_Logging-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bcd646b73f81d65da97cb93cbb1d75918fd0f0ddff89e07fcea6c069f6c12de0
MD5 7ba4b1f8adf20d5e6665e11dc054a001
BLAKE2b-256 1bd439d70ce2caa600b7db3502c0a7afcd108ec759ecae73d3d2506dda32f903

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page