A simple log module based logging for python.
Project description
log4p
Simple log module for python.
Usage
Install:
pip install log4p
Add to you script, eg: python a_test_file.py
#-*- coding:utf8 -*-
import log4p
logger = log4p.GetLogger(__name__)
log = logger.logger
log.debug("Hello Tianfei Hao!")
log.info("Enjoy your happy time!")
log.error("If you have any better Suggestions, please contact Tianfei Hao at talenhao@gmail.com")
log.warning("Thanks for star on github: https://github.com/talenhao/log4p")
demo
(log4p) [Sat Jul 13 talen@tp-arch-tianfei log4p]$ python a_test_file.py
2019-07-13 02:23:42,664 - __main__ - INFO - Enjoy your happy time!
2019-07-13 02:23:42,664 - __main__ - ERROR - If you have any better Suggestions, please contact Tianfei Hao at talenhao@gmail.com
2019-07-13 02:23:42,664 - __main__ - WARNING - Thanks for star on github: https://github.com/talenhao/log4p
[Sat Jul 13 talen@tp-arch-tianfei log4p]$ ls -l *.log
-rw-r--r-- 1 talen users 1195 Jul 13 01:25 log4p-debug.log
-rw-r--r-- 1 talen users 0 Jul 13 00:58 log4p-errors.log
(log4p) [Sat Jul 13 talen@tp-arch-tianfei log4p]$ cat log4p-errors.log
2019-07-13 02:23:42,664 ERROR a_test_file.py +7 <module> [MainThread]: If you have any better Suggestions, please contact Tianfei Hao at talenhao@gmail.com
(log4p) [Sat Jul 13 talen@tp-arch-tianfei log4p]$ cat log4p-debug.log
2019-07-13 02:23:42,664 DEBUG a_test_file.py +5 <module> [MainThread]: Hello Tianfei Hao!
2019-07-13 02:23:42,664 INFO a_test_file.py +6 <module> [MainThread]: Enjoy your happy time!
2019-07-13 02:23:42,664 ERROR a_test_file.py +7 <module> [MainThread]: If you have any better Suggestions, please contact Tianfei Hao at talenhao@gmail.com
2019-07-13 02:23:42,664 WARNING a_test_file.py +8 <module> [MainThread]: Thanks for star on github: https://github.com/talenhao/log4p
Config file:
- Default config file path:
<module dir>/log4p.json
~/.virtualenvs/<your pyenv>/lib/python3.7/site-packages/log4p/log4p.json
- In my notebook, it's in:
/home/talen/.virtualenvs/log4p/lib/python3.7/site-packages/log4p/log4p.json
- You can use your own config file when invoke log4p.GetLogger(config=<your config file path>)
- Default config file content is:
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"detail": {
"format": "%(asctime)-15s %(levelname)-5s %(filename)s +%(lineno)d %(funcName)s [%(threadName)s]: %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"debug_file_handler": {
"class": "logging.handlers.TimedRotatingFileHandler",
"level": "DEBUG",
"formatter": "detail",
"filename": "log4p-debug.log",
"when": "D",
"interval": 1,
"backupCount": 30,
"encoding": "utf8"
},
"error_file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"formatter": "detail",
"filename": "log4p-errors.log",
"maxBytes": 10485760,
"backupCount": 2,
"encoding": "utf8"
}
},
"loggers": {
"my_module": {
"level": "ERROR",
"handlers": ["console"],
"propagate": "no"
}
},
"root": {
"level": "INFO",
"handlers": ["console", "debug_file_handler", "error_file_handler"]
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
log4p-2019.7.13.3.tar.gz
(16.7 kB
view details)
Built Distribution
File details
Details for the file log4p-2019.7.13.3.tar.gz
.
File metadata
- Download URL: log4p-2019.7.13.3.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91c657bdb3b02dfd16277b0b26717dfec98bff5dd171d6797b326da5f96a442e |
|
MD5 | 9937140223dc05cf2abb20200222da25 |
|
BLAKE2b-256 | a1851ea7a4656f68b45f5d26b9175423c6a875d62637cdfea6f1991c691ae0d1 |
File details
Details for the file log4p-2019.7.13.3-py2.py3-none-any.whl
.
File metadata
- Download URL: log4p-2019.7.13.3-py2.py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203d41b3a5d9f18411db90e75ae1ea103fcdce19700e5f0a22ba3f304430bf3f |
|
MD5 | 608df9efbad67bae3d21acaa58c1afd5 |
|
BLAKE2b-256 | 2db7b2f563f4bc324c1292c281346a825a8f074049a466749a759486080c69df |