Skip to main content

Configure Graylog logging handlers and middleware for your Flask app

Project description

This is a Flask extension that allows you to configure a Graylog log handler as well as configuring middleware to log every request/response to Graylog.

Installation

You can install it via pip:

pip install Flask-Graylog

Usage

You only need to import and initialize your app

# Import dependencies
from flask import Flask
from flask.ext.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.ext.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 the extra data 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 -"
 }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-Graylog-1.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Flask_Graylog-1.1.0-py2-none-any.whl (4.0 kB view details)

Uploaded Python 2

File details

Details for the file Flask-Graylog-1.1.0.tar.gz.

File metadata

  • Download URL: Flask-Graylog-1.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-Graylog-1.1.0.tar.gz
Algorithm Hash digest
SHA256 46e828b9ab3e148b2d85a38574939bfc8d637238e870f1ded9f6b87a6e2ed097
MD5 976c0d491925460842eeab944e9f7eca
BLAKE2b-256 f97305f9eb8bcb4622b676c302162e0b836cc2fa2e58448db5f6553201408941

See more details on using hashes here.

File details

Details for the file Flask_Graylog-1.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for Flask_Graylog-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 c99f5d5f88edd516af571047a4874b58eca810e2a1914d065dc0991259905af1
MD5 17d6467a3a862557d581864ee5e827a9
BLAKE2b-256 517fe4668b5280b3017f47a7f45e223b39f830b1843e7ebd42ab8ecb497b816d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page