# SingleLog
[![Package Version](https://img.shields.io/pypi/v/SingleLog.svg)](https://pypi.python.org/pypi/SingleLog)
[![test](https://github.com/PttCodingMan/SingleLog/actions/workflows/test.yml/badge.svg)](https://github.com/PttCodingMan/SingleLog/actions/workflows/test.yml)
![PyPI - Downloads](https://img.shields.io/pypi/dm/SingleLog)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/SingleLog)
### SingleLog is a simple library for logging. It is designed to make logging easier.
### It can format your data and output it to the console or file.
### It can also log your event status step by step.
### Note: If you have problems while using SingleLog and other libraries, you can try `DefalutLogger` instead of `SingleLogger`.
## Quick View
### Stage Method
You can use `stage` method to display the log step by step in the same line.
And don't need to worry about the default print function will print the log in the same line.
> Note that the stage effect only works on LogLevel.INFO.
```python
import time
from SingleLog import Logger
logger = Logger('rocket')
logger.info('Init rocket launch proces')
time.sleep(1.5)
logger.stage('complete!')
logger.info('Start the countdown')
time.sleep(1)
logger.stage('3')
time.sleep(1)
logger.stage('2')
time.sleep(1)
logger.stage('1')
time.sleep(1)
logger.stage('fire!')
logger.info('Launch complete')
```
![](https://imgur.com/0nYvBcd.gif)
### Automatic Data Format
SingleLog Supports some common types to display in format. Such as list, dict and tuple etc.
```python
from SingleLog import Logger
logger = Logger('demo')
logger.info('show int list', [101, 102, 103])
logger.info('show tuple', ('12', '14', '16'))
logger.info('data', {'1': 'value1', '2': 'value2'})
```
![](https://imgur.com/EVudUBb.jpg)
## Install
```
pip install SingleLog -U
```
## Basic Usage
```python
from SingleLog import Logger
logger = Logger('demo')
logger.info('hello world')
```
### Log Levels
You can set the [LogLevel](https://github.com/PttCodingMan/SingleLog/blob/master/SingleLog/log.py) of the logger.
- `info`: Confirmation that things are working as expected.
- `debug`: Detailed information, usually of interest only when diagnosing problems.
- `trace`: Detailed information on the flow through the system.
```python
from SingleLog import Logger
from SingleLog import LogLevel
logger = Logger('demo', log_level=LogLevel.DEBUG)
logger.info('you can see it, when log_level is set to INFO, DEBUG and TRACE')
logger.debug('you can see it, when log_level is set to DEBUG and TRACE')
logger.trace('you can see it, when log_level is set to TRACE')
```
### Logger Handler
You can use logger handler to handle the log.
```python
from SingleLog import Logger
def log_to_file(msg):
with open('single_log.txt', 'a', encoding='utf8') as f:
f.write(f'{msg}\n')
logger = Logger('Handle', handler=log_to_file)
logger.info('1')
logger.info(2)
logger.info('show value', 456)
```
Handler also supports list.
```python
from SingleLog import Logger
from SingleLog import LogLevel
def log_to_file(msg):
with open('single_log.txt', 'a', encoding='utf8') as f:
f.write(f'{msg}\n')
def log_to_file2(msg):
with open('single_log_2.txt', 'a', encoding='utf8') as f:
f.write(f'{msg}\n')
logger = Logger('INFO', LogLevel.INFO, handler=[log_to_file, log_to_file2])
logger.info('1')
logger.info(2)
logger.info('show value', 456)
```
In this demo, the log message will display on the screen.
Also you can find it in single_log.txt and single_log_2.txt.
## Advanced Usage
You can use logger to display the log in different ways.
### Skip Repeated Message
You can skip repeated message.
The following logger will display only one message.
```python
from SingleLog import Logger
logger = Logger('demo', skip_repeat=True)
logger.info('hello world')
logger.info('hello world')
logger.info('hello world')
```
### Stage Separator
You can change stage separator to display the log.
```python
import time
from SingleLog import Logger
logger = Logger('demo', stage_sep='-')
logger.info('Init rocket launch proces')
time.sleep(1.5)
logger.stage('complete!')
logger.info('Start the countdown')
time.sleep(1)
logger.stage('3')
time.sleep(1)
logger.stage('2')
time.sleep(1)
logger.stage('1')
```
![](https://imgur.com/6FZoLYD.jpeg)
### Stage Color
You can change stage color.
You can find the more color information from [Colorama](https://github.com/tartley/colorama).
```python
from colorama import Fore
from SingleLog import Logger
logger = Logger('demo', stage_color_list = [Fore.GREEN, Fore.YELLOW])
logger.info('start')
for i in range(10):
logger.stage(i)
```
![](https://imgur.com/B06f3iM.jpeg)
### Timestamp
You can change timestamp format.
```python
from SingleLog import Logger
logger = Logger('demo')
logger.info('default timestamp')
logger = Logger('demo', timestamp='%Y-%m-%d %H:%M:%S')
logger.info('custom timestamp')
```
![](https://imgur.com/P0NGMf6.jpeg)
### Keyword of success and failure
You can use keyword of success and failure to display the log.
The keywords in `key_word_success`, will be displayed in green color.
The keywords in `key_word_failure`, will be displayed in red color.
```python
from SingleLog import Logger
logger = Logger('demo', key_word_success=['custom_success'], key_word_fails=['custom_fail'])
logger.info('do something')
logger.stage('custom_success')
logger.stage('custom_fail')
```
![](https://imgur.com/fjymmFq.jpeg)
## License
MIT License
Raw data
{
"_id": null,
"home_page": "https://github.com/PttCodingMan/SingleLog",
"name": "SingleLog",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "log,logger,library",
"author": "CodingMan",
"author_email": "pttcodingman@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/66/4d/01a9a19a60127030446c605f397d90b333cea59858f9f644b1657edb17a5/SingleLog-2.1.1.tar.gz",
"platform": null,
"description": "# SingleLog\n[![Package Version](https://img.shields.io/pypi/v/SingleLog.svg)](https://pypi.python.org/pypi/SingleLog)\n[![test](https://github.com/PttCodingMan/SingleLog/actions/workflows/test.yml/badge.svg)](https://github.com/PttCodingMan/SingleLog/actions/workflows/test.yml)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/SingleLog)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/SingleLog)\n\n### SingleLog is a simple library for logging. It is designed to make logging easier.\n### It can format your data and output it to the console or file.\n### It can also log your event status step by step.\n\n### Note: If you have problems while using SingleLog and other libraries, you can try `DefalutLogger` instead of `SingleLogger`.\n\n## Quick View\n\n### Stage Method\nYou can use `stage` method to display the log step by step in the same line. \nAnd don't need to worry about the default print function will print the log in the same line.\n\n> Note that the stage effect only works on LogLevel.INFO.\n\n```python\nimport time\nfrom SingleLog import Logger\n\nlogger = Logger('rocket')\n\nlogger.info('Init rocket launch proces')\ntime.sleep(1.5)\nlogger.stage('complete!')\n\nlogger.info('Start the countdown')\ntime.sleep(1)\nlogger.stage('3')\ntime.sleep(1)\nlogger.stage('2')\ntime.sleep(1)\nlogger.stage('1')\ntime.sleep(1)\nlogger.stage('fire!')\nlogger.info('Launch complete')\n```\n\n![](https://imgur.com/0nYvBcd.gif)\n\n### Automatic Data Format\nSingleLog Supports some common types to display in format. Such as list, dict and tuple etc.\n\n```python\nfrom SingleLog import Logger\n\nlogger = Logger('demo')\nlogger.info('show int list', [101, 102, 103])\nlogger.info('show tuple', ('12', '14', '16'))\nlogger.info('data', {'1': 'value1', '2': 'value2'})\n```\n\n![](https://imgur.com/EVudUBb.jpg)\n\n## Install\n```\npip install SingleLog -U\n```\n\n## Basic Usage\n```python\nfrom SingleLog import Logger\n\nlogger = Logger('demo')\n\nlogger.info('hello world')\n```\n\n### Log Levels\nYou can set the [LogLevel](https://github.com/PttCodingMan/SingleLog/blob/master/SingleLog/log.py) of the logger.\n\n- `info`: Confirmation that things are working as expected.\n- `debug`: Detailed information, usually of interest only when diagnosing problems.\n- `trace`: Detailed information on the flow through the system.\n\n\n```python\nfrom SingleLog import Logger\nfrom SingleLog import LogLevel\n\nlogger = Logger('demo', log_level=LogLevel.DEBUG)\n\nlogger.info('you can see it, when log_level is set to INFO, DEBUG and TRACE')\nlogger.debug('you can see it, when log_level is set to DEBUG and TRACE')\nlogger.trace('you can see it, when log_level is set to TRACE')\n```\n\n### Logger Handler\nYou can use logger handler to handle the log.\n```python\nfrom SingleLog import Logger\n\ndef log_to_file(msg):\n with open('single_log.txt', 'a', encoding='utf8') as f:\n f.write(f'{msg}\\n')\n\n\nlogger = Logger('Handle', handler=log_to_file)\n\nlogger.info('1')\nlogger.info(2)\nlogger.info('show value', 456)\n```\nHandler also supports list.\n```python\nfrom SingleLog import Logger\nfrom SingleLog import LogLevel\n\ndef log_to_file(msg):\n with open('single_log.txt', 'a', encoding='utf8') as f:\n f.write(f'{msg}\\n')\n\ndef log_to_file2(msg):\n with open('single_log_2.txt', 'a', encoding='utf8') as f:\n f.write(f'{msg}\\n')\n\n\nlogger = Logger('INFO', LogLevel.INFO, handler=[log_to_file, log_to_file2])\n\nlogger.info('1')\nlogger.info(2)\nlogger.info('show value', 456)\n```\nIn this demo, the log message will display on the screen. \nAlso you can find it in single_log.txt and single_log_2.txt.\n\n## Advanced Usage\nYou can use logger to display the log in different ways.\n\n### Skip Repeated Message\nYou can skip repeated message. \nThe following logger will display only one message.\n\n```python\nfrom SingleLog import Logger\n\nlogger = Logger('demo', skip_repeat=True)\n\nlogger.info('hello world')\nlogger.info('hello world')\nlogger.info('hello world')\n```\n\n### Stage Separator\n\nYou can change stage separator to display the log.\n\n```python\nimport time\nfrom SingleLog import Logger\n\nlogger = Logger('demo', stage_sep='-')\n\nlogger.info('Init rocket launch proces')\ntime.sleep(1.5)\nlogger.stage('complete!')\n\nlogger.info('Start the countdown')\ntime.sleep(1)\nlogger.stage('3')\ntime.sleep(1)\nlogger.stage('2')\ntime.sleep(1)\nlogger.stage('1')\n```\n\n![](https://imgur.com/6FZoLYD.jpeg)\n\n### Stage Color\nYou can change stage color. \nYou can find the more color information from [Colorama](https://github.com/tartley/colorama).\n\n```python\nfrom colorama import Fore\nfrom SingleLog import Logger\n\nlogger = Logger('demo', stage_color_list = [Fore.GREEN, Fore.YELLOW])\n\nlogger.info('start')\nfor i in range(10):\n logger.stage(i)\n```\n\n![](https://imgur.com/B06f3iM.jpeg)\n\n### Timestamp\nYou can change timestamp format.\n\n```python\nfrom SingleLog import Logger\n\nlogger = Logger('demo')\nlogger.info('default timestamp')\n\nlogger = Logger('demo', timestamp='%Y-%m-%d %H:%M:%S')\nlogger.info('custom timestamp')\n```\n\n![](https://imgur.com/P0NGMf6.jpeg)\n\n### Keyword of success and failure\nYou can use keyword of success and failure to display the log. \n\nThe keywords in `key_word_success`, will be displayed in green color. \nThe keywords in `key_word_failure`, will be displayed in red color. \n\n```python\nfrom SingleLog import Logger\n\nlogger = Logger('demo', key_word_success=['custom_success'], key_word_fails=['custom_fail'])\n\nlogger.info('do something')\nlogger.stage('custom_success')\nlogger.stage('custom_fail')\n```\n\n![](https://imgur.com/fjymmFq.jpeg)\n\n## License\nMIT License\n",
"bugtrack_url": null,
"license": "",
"summary": "# SingleLog",
"version": "2.1.1",
"split_keywords": [
"log",
"logger",
"library"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "bb86f552756542b47988a8c3ae241691",
"sha256": "2c5bd7723ff603775cba811362d739260eb1d442b9454bbadc82fafb5e27077f"
},
"downloads": -1,
"filename": "SingleLog-2.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bb86f552756542b47988a8c3ae241691",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8678,
"upload_time": "2022-12-20T09:21:46",
"upload_time_iso_8601": "2022-12-20T09:21:46.968509Z",
"url": "https://files.pythonhosted.org/packages/5e/ad/b45863906a13960a83824a7cb925e35007f2a65cc1d085601ac89cc4546c/SingleLog-2.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "a90f20df749524f9b050016988739f84",
"sha256": "adc8d2702ea039b83957c5a247b3f40949ca55ac630e2a712e10207370fa2e16"
},
"downloads": -1,
"filename": "SingleLog-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a90f20df749524f9b050016988739f84",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 1363371,
"upload_time": "2022-12-20T09:21:48",
"upload_time_iso_8601": "2022-12-20T09:21:48.761559Z",
"url": "https://files.pythonhosted.org/packages/66/4d/01a9a19a60127030446c605f397d90b333cea59858f9f644b1657edb17a5/SingleLog-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-20 09:21:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "PttCodingMan",
"github_project": "SingleLog",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "colorama",
"specs": []
},
{
"name": "AutoStrEnum",
"specs": []
}
],
"lcname": "singlelog"
}