Skip to content

Commit

Permalink
Added Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
2press committed Jan 7, 2019
1 parent 4b4cf5a commit e9199e8
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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})
```

0 comments on commit e9199e8

Please sign in to comment.