From e9199e8b246c03a2b8667967eaa911b8a8556c7b Mon Sep 17 00:00:00 2001 From: 2press Date: Mon, 7 Jan 2019 18:58:01 +0100 Subject: [PATCH] Added Readme --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/README.md b/README.md index e69de29..5e666b1 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,67 @@ +[![](https://img.shields.io/pypi/v/sc2monitor.svg)](https://pypi.org/project/sc2monitor/) + +# discord-logger +A Python logger to send information to Discord Webhooks. + +## Installation +Install this package via `pip` by executing `pip install discordlogger` + +## Usage + +### Basic Usage + +```python +import logging + +from discordlogger import DiscordFormatter + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +h = DiscordHandler(webhook_url=URL) +h.setLevel(logging.INFO) +logger.addHandler(h) + +logger.info('Hello World') +``` + +### Advanced Formating + +```python +import logging + +from discordlogger import DiscordFormatter, DiscordHandler + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +h = DiscordHandler(webhook_url=URL) +h.formatter = DiscordFormatter() +logger.addHandler(h) + +logger.info('Hello World') +logger.warning('Warning!') +try: + print(data['hello']) +except Exception: + logger.exception('Exception!') +logger.critical('Emergency here!') +``` + +### Filtering + +```python +import logging + +from discordlogger import DiscordFormatter, DiscordLogFilter + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +h = DiscordHandler(webhook_url=URL) +h.addFilter(DiscordLogFilter()) +logger.addHandler(h) + +# Now this doesn't activate the discord webhook +logger.info("Hello World") + +# Whereas this does +logger.info("Hello World", extra={'notify_discord': True}) +```