Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betodealmeida/consolelog
Log to browser console from Python
https://github.com/betodealmeida/consolelog
browser console logging python
Last synced: 4 months ago
JSON representation
Log to browser console from Python
- Host: GitHub
- URL: https://github.com/betodealmeida/consolelog
- Owner: betodealmeida
- License: mit
- Created: 2018-03-21T20:50:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T15:33:37.000Z (about 2 years ago)
- Last Synced: 2024-09-26T03:23:31.953Z (5 months ago)
- Topics: browser, console, logging, python
- Language: Python
- Size: 350 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# console_log #
This module provides a WSGI middleware that allows you to log to the browser console from Python:
```python
import loggingfrom flask import Flask
from console_log import ConsoleLog
console = logging.getLogger('console')
console.setLevel(logging.DEBUG)app = Flask(__name__)
@app.route('/')
def hello():
logger.error('Error logged from Python')
logger.warning('Warning logged from Python')
logger.info('Info logged from Python')
logger.debug('Debug logged from Python')
logger.debug({'foo': ['bar', 'baz']})
return "Hello World!"app.wsgi_app = ConsoleLog(app.wsgi_app, console)
```The logged messages will then show up in the browser console:
![Example showing messages in console](https://github.com/betodealmeida/consolelog/blob/master/docs/console_log.png)
# How it works #
The new WSGI app does two things:
1. Creates a websocket backchannel.
2. Injects Javascript code into HTML responses, fetching data from the websocket channel and logging them to console.