Giter Site home page Giter Site logo

flask-graylog's Introduction

Flask-Graylog

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 -"
 }

flask-graylog's People

Contributors

brettlangdon avatar captify-alazorenko avatar onewiththecore avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.