An uncomplicated way to use logger inside python applications
Project description
PHK-Logger
An uncomplicated way to use logger inside python applications
- Created at: 01/05/2020
- Updated at:
- Author: Ben Mz (bmz)
- Maintainer: Ben Mz (bmz)
- Client: ProHacktive (https://prohacktive.io)
Install
The easy way is by using pip
pip install phk-logger
The harder way is from sources
git clone https://github.com/proh4cktive/phk-logger.git
cd phk-logger
python install setup.py
Usage
PHK-Logger is a lib so you just have to import it when needed
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from phk_logger import PHKLogger as Logger
Then in your code you can instantiate it directly
logger = Logger(name='mytest', cli=True)
And use it when needed
logger.info('This is an info message') # Will not be printed as default level is Warning
logger.write('A blue warning', level='warning', color='blue')
Options
PHK-Logger is configred by default to output log event to your SysLog sub-system (Only supports Linux/MacOS). Some additional options can be set in order to change this behaviour.
- name Set a specific name to your logger stream, by default will use the
__name__var. - level Set the log level, must be a level from logging package
- filename If set phk-logger will output events to a specific filename using TimedRotatingFileHandler configured with a file rotating every midnight, and 3 backup files
- backup Only used if filename is configured, specifiy the number of backup to keep
- when Only used if filename is configured, specify when to execute the file rotation
- cli If set to True this will also output log event to command line interface (CLI). Only useful for debugging app.
- pattern Define the log pattern to use for event output. Default is
%(name)s %(asctime)s %(levelname)-8s %(message)s
Methods
Several methods can be used to generate event logs, they all support the same options (only usefuls when using cli flag):
- msg: the message to output
- color: override the default color
- light: override the light mode
- debug(msg, color='blue', light=True) output event with prefix:
[*]- info(msg, color='green', light=False) output event with prefix:
[+]- warning(msg, color='yellow', light=False) output event with prefix:
[-]- error(msg, color='red', light=False) output event with prefix:
[!]- critical(msg, color='red', light=True) output event with prefix:
[!]
An additional method is accessible which support a level parameter
- write(message, level=None, color=None, light=None)
Colors
Multiple colors are supported (case insensitive)
- BLACK
- BLUE
- GREEN
- CYAN
- RED
- PURPLE
- YELLOW
- WHITE
- no-color (default)
Levels
Multiple levels are supported (case insensitive)
- DEBUG
- INFO
- INFOS
- WARNING
- ERROR
- CRITICAL
Tests
Run tests easily using pytest
pytest -vv
TODO
- Doc
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phk_logger-0.1.4.tar.gz.
File metadata
- Download URL: phk_logger-0.1.4.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.6.9 Linux/4.15.0-1079-oem
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5e978946f238e04d59b4a4f7625d15931b65393284c1cd897498a13a8ad6d0e
|
|
| MD5 |
de9557eab1ee0c300aaed45967d8fd5d
|
|
| BLAKE2b-256 |
c49521894a03f971887285872b60258ac778e3a131a95a56dbc00da551374b8c
|
File details
Details for the file phk_logger-0.1.4-py3-none-any.whl.
File metadata
- Download URL: phk_logger-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.6.9 Linux/4.15.0-1079-oem
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0407b3599f5d1633e1a18ad588bb4b4a71798bd2de946414893f9c24d3ac96
|
|
| MD5 |
a35d91c8afa407ecaa4f41cfd4ed356b
|
|
| BLAKE2b-256 |
181b9d132166b80e53fac87eea22efe16c3e3880f028d8980f8a7c25d083d345
|