Updated Development_LogCapture (markdown)

Chris Caron 2020-10-13 14:45:16 -04:00
parent 3be2715749
commit c08eeec033

@ -90,3 +90,27 @@ with apprise.LogCapture(
## Class Details
- By default if no `level=` is specified, then the log level you set globally in your program is used.
### Tricks
Format your logs for HTML:
```python
# The default fmt for LogCapture() is: '%(asctime)s - %(levelname)s - %(message)s'
# But you can use this to leverage how you want the content formatted; so you can
# build your HTML content in advance here if you like:
fmt = '<li><i class="log_time">%(asctime)s</i>' \
'<i class="log_level">%(levelname)s</i>:' \
'<p class="log_msg">%(message)s</p></li>'
# Now specify our format (and over-ride the default):
with apprise.LogCapture(level=apprise.logging.WARNING, fmt=fmt) as logs:
apobj.notify("hello world")
# Wrap logs in `<ul>` tag:
html = '<ul class="logs">{}</ul>'.format(logs.getvalue())
# Now `html` consists of a formatted code; keep in mind that
# this solution isn't bulletproof as `%(message)s` isn't
# pre-escaped/encoded.
```