Skip to main content

clinlog

PyPI version PyPI version

Package to easily log styled messages on console


Basic usage

Create a Logger object and use his convenient methods to print styled messages in console. You can define a default tag for each kind of message on the Logger instance. There is a custom handler to use clinlog with default loggign package of python stdlib (Using custom handler expanation below).

Print style methods

  • confirm()
  • error()
  • warning()
  • info()
  • debug()
  • print()

The signature for all print methods are the same:

  1. message (str): Message to print.
  2. tag (str): (Optional) Prefix tag to print with the message. If None the default tag for this kind of messages is used. An empty string will remove the tag for this print.
  3. bold (bool): (Optional) True to use bright style to print the message (kind of bold font). By default False.
  4. highlight (bool): True to use the color on the background and a high contrast color for the message text.
  5. invert_color (bool): True to invert font color when highlight flag is on, this will switch between black and white. By default False.

Default print tag attributes

When a Logger object is created all default tags are an empty string (no tag)

  • confirm_tag
  • error_tag
  • warn_tag
  • info_tag
  • print_tag

Log level param

You can provide a log level parameter to control the verbosity of the logger, this parameter can be provided during construction or via setter method. By default Logger class takes max verbosity level (debug)

from clinlog import Logger

# Creating a Logger with warining log level
log = Logger(log_level='warning')

# Updating log level via setter
log.log_level = 'debug'

Code Sample

from clinlog import Logger

# Create the logger
log = Logger()

# Set default error tag
log.error_tag = '[ERROR]: '

# Print error styled message
log.error('Unable to access config file', bold=True)

# Print warning highlighted and bold
log.warning('The execution will continue with default configuration', None, True, True)

# Confirmation log with provided tag
log.confirm('Execution completed', '[SUCCESS]')

# Debug log with provided tag
log.debug('DB returned 8 entries for the user', '[DEBUG] ')

Output

tree_output

Different styes sample

tree_output

ClinlogHandler and python logging package

To use Clinlog with python logging package you can create an instance of ClinlogHandler and add it to your custom logger handlers. There are two convinent funcions to create a logging.Logger whith this handler setted.

First here is an example of how to create a logger from logging package and add ClinlogHandler to print styled messages when logging.

import logging

from clinlog.logging import ClinlogHandler


# Create logger and handler
logger = logging.getLogger('clinlog')
cl_handler = ClinlogHandler()

# Set log level and add Clinlog handler to logger
logger.setLevel(logging.DEBUG)
logger.addHandler(cl_handler)

logger.critical('This is a critical error!')
logger.error('This is an error')
logger.warning('Some warning')
logger.info('Everithing is going right for now')
logger.debug('User input was 4')

About the helper functions you can use them to create (create_logger()) or get the logger (get_logger()) directly.

import logging

from clinlog.logging import get_logger, create_logger

# Creates logger with name 'clinlog'
create_logger()

# You can get the logger with logging
logger = logging.getLogger('clinlog')

# For ease of use get_logger() creates (if needed, so you don't need to call creeate_logger before this) clinlog logger and returns it
logger = get_logger()

logger.info('Logging setted up')

ClinlogHandler details

  • ClinlogHandler extends from StreamHandler from logging package, so you can expect same methods as this handler.
  • The handles is by default in DEBUG level.
  • The message formater is by default with format: [%(levelname)s] %(message)s (you can see an output examples below)

ClinlogHandler output

handler_output

Metadata

Release files for clinlog 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clinlog 1.0.0
File Size Uploaded Provenance
clinlog-1.0.0.tar.gz 7.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for clinlog 1.0.0
File Interpreter ABI Platform
clinlog-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / clinlog-1.0.0.tar.gz

Download URL clinlog-1.0.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
378fb2ca46139bfef0f885565840b8e05133ce21db4529eb908bc329bf61c199
BLAKE2b-256 checksum
How to use checksums
d27a9538c05637f8a2021cabb1c12f85117a1eb08860366ff7487840365d281f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

Release files / clinlog-1.0.0-py3-none-any.whl

Download URL clinlog-1.0.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47244bf06bf9100acbf4a5e439486d1b3ebde18cfc3ea27ca685193ab00024df
BLAKE2b-256 checksum
How to use checksums
87b527bf36467fad777a2ff542237ca841e1ed9a72bbfdc5a83d83821d63cf8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

Security for clinlog 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page