Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
you can install the following library simply by just running:
pip install logging-colorizer
In addition to use this library first we need to import it using:
from logging_colorizer import Log
after that we instantiate our logger and we also can costumize its format
log = Log() #this is the logger with its default settings
log = Log(format="%(light_black)s TIME: %(asctime)s %(cyan)s|%(light_black)s IP: %(clientip)s %(cyan)s|%(light_black)s CODE: %(Code)s %(cyan)s|%(purple)s [%(lvl)s] %(cyan)s|%(log_color)s %(message)s %(reset)s") # this is the logger with costumized format like so
Level | Default function name | Abbriviation | Shortened name |
---|---|---|---|
Info | info | inf | i |
warning | warning | warn | w |
debug | debug | dbg | d |
error | error | err | e |
critical | critical | crit | c |
So all of three lines bellow do the exact same thing
log.info('Here is the info')
log.inf('Here is the info')
log.i('Here is the info')
And so on...
For using different colors in your logger you should provide the color on the format argument of the module like this:
log = Log(format="%(purple)s %(message)s %(reset)s")
in the above example in every call of the logger, it writes the message in purple color and then resets the color for future logs.(just incase if there were no colors provided)
instead of purple, you can use these colors:
A boilerplate code can be like this:
# Imports
from logging_colorizer import Log
import requests
# A function that gets the current IP address
def check_ip():
session = requests.session()
ip = session.get("http://icanhazip.com").text.replace("\n","")
session.close()
return ip
ip = check_ip() # Run the function to get the ip
log = Log(format="%(light_black)s TIME: %(asctime)s %(cyan)s|%(light_black)s IP: %(clientip)s %(cyan)s|%(light_black)s CODE: %(Code)s %(cyan)s|%(purple)s [%(lvl)s] %(cyan)s|%(log_color)s %(message)s %(reset)s") # Initializing our logging module with our custom format
log.info('Here is an info log', extra_plus_ali={'clientip': ip, "Code": "Boilerplate.py"})
log.warning('Here is a warning log', extra_plus_ali={'clientip': ip, "Code": "Boilerplate.py"})
log.debug('Here is a debug log', extra_plus_ali={'clientip': ip, "Code": "Boilerplate.py"})
log.error('Here is an error log', extra_plus_ali={'clientip': ip, "Code": "Boilerplate.py"})
log.critical('Here is a critical log', extra_plus_ali={'clientip': ip, "Code": "Boilerplate.py"})
Which returns an output like bellow:
FAQs
This library is based on the requests library but it colorizes the logs.
We found that logging-colorizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.