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"]
}
}
Metadata
Release files for log4p 2019.7.13.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| log4p-2019.7.13.3.tar.gz | 16.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| log4p-2019.7.13.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 32.7 kB
Release files / log4p-2019.7.13.3.tar.gz
| Download URL | log4p-2019.7.13.3.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91c657bdb3b02dfd16277b0b26717dfec98bff5dd171d6797b326da5f96a442e
|
|
BLAKE2b-256 checksum How to use checksums |
a1851ea7a4656f68b45f5d26b9175423c6a875d62637cdfea6f1991c691ae0d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / log4p-2019.7.13.3-py2.py3-none-any.whl
| Download URL | log4p-2019.7.13.3-py2.py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
203d41b3a5d9f18411db90e75ae1ea103fcdce19700e5f0a22ba3f304430bf3f
|
|
BLAKE2b-256 checksum How to use checksums |
2db7b2f563f4bc324c1292c281346a825a8f074049a466749a759486080c69df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|