This project has been archived by its maintainers, and is no longer receiving any updates.
Flask-Graylog2
Fork of github.com/underdogio/flask-graylog with additional patches and features.
This is a Flask extension that allows you to configure a Graylog GELF UDP logging handler as well as some middleware to log every request/response pair to Graylog.
See also:
Installation
You can install it with pip:
$ pip install Flask-Graylog2
Usage
You only need to import and initialize your app
# Import dependencies
from flask import Flask
from flask_graylog import Graylog
# Configure app and Graylog logger
app = Flask(__name__)
graylog = Graylog(app)
# Log to graylog
graylog.info("Message", extra={"extra": "metadata",})
# Use Graylog log handler in another logger
import logging
logger = logging.getLogger(__name__)
logger.addHandler(graylog.handler)
logger.info("Message")
Configuration options
The following options can be use to configure the graylog logger.
from flask import Flask
from flask_graylog import Graylog
app = Flask(__name__)
# Use configuration from `app`
app.config["GRAYLOG_HOST"] = "10.1.1.1"
graylog = Graylog(app)
# Provide configuration
config = {"GRAYLOG_HOST": "10.1.1.1"}
graylog = Graylog(app, config=config)
GRAYLOG_HOST- the host to send messages to [default: 'localhost']GRAYLOG_PORT- the port to send messages to [default: 12201]GRAYLOG_FACILITY- the facility to report with [default: 'flask']GRAYLOG_EXTRA_FIELDS- whether or not to include theextradata from each message [default: True]GRAYLOG_ADD_DEBUG_FIELDS- whether extra python debug fields should be added to each message [default: True]GRAYLOG_CONFIGURE_MIDDLEWARE- whether to setup middleware to log each response [default: True]
Example message format
{
"_process_name": "MainProcess",
"_request": {
"content_length": "",
"remote_addr": "127.0.0.1",
"headers": {
"upgrade_insecure_requests": "1",
"connection": "keep-alive",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"dnt": "1",
"host": "localhost:5000",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36",
"accept_language": "en-US,en;q=0.8,ms;q=0.6",
"cache_control": "max-age=0",
"accept_encoding": "gzip, deflate, sdch"
},
"path_info": "/",
"content_type": "",
"query_string": "",
"method": "GET"
},
"level": 6,
"_logger": "flask_graylog",
"timestamp": 1460502169.950895,
"_pid": 6010,
"facility": "flask",
"_function": "after_request",
"_thread_name": "Thread-1",
"host": "voltaire.local",
"version": "1.0",
"file": "Flask-Graylog/flask_graylog.py",
"full_message": "Finishing request for \"GET http://localhost:5000/\" from -",
"line": 130,
"_response": {
"headers": {
"content_length": "6",
"content_type": "text/html; charset=utf-8"
},
"time_ms": 0,
"status_code": 200
},
"_flask": {
"view_args": {},
"endpoint": "root"
},
"short_message": "Finishing request for \"GET http://localhost:5000/\" from -"
}
Metadata
Release files for Flask-Graylog2 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-Graylog2-1.2.2.tar.gz | 6.6 kB | Without provenance | Details for Flask-Graylog2-1.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_Graylog2-1.2.2-py3-none-any.whl | Python 3 | none | any | Details for Flask_Graylog2-1.2.2-py3-none-any.whl |
Total release size: 12.2 kB
Release files / Flask-Graylog2-1.2.2.tar.gz
| Download URL | Flask-Graylog2-1.2.2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
813be5073c00c9802e1188d0c6eadcc09c30004e97c305b26d0c0652af228bed
|
|
BLAKE2b-256 checksum How to use checksums |
d16ec233fdd4aa75f69ed24d159a3cefc13a8dc946037b9a0ae0adc9f27b35b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.23.0
|
Release files / Flask_Graylog2-1.2.2-py3-none-any.whl
| Download URL | Flask_Graylog2-1.2.2-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb50d47c6c8c5693321f60ddf349699fa360c3561fe0a4eb26d0cac7d607ec6c
|
|
BLAKE2b-256 checksum How to use checksums |
8fef5cee7db1e0fee5d4722dbe7eff82e1e5cd2c82523d040b08d1336b49be0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.23.0
|
Security for Flask-Graylog2 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.