Skip to main content

Enables web traffic and request logs for your Flask app.

Project description

Flask-Web-Log

Flask-Web-Log enables request logging for your flask app. It has support for multiple

Features

The following useful request data is logged (full explanations are in the Flask docs):

  • time: Date and Time in ISO 8601 format
  • src_ip: Source IP, has support for 'X-Forwarded-For'
  • useragent: Client UserAgent
  • connection: Connection Type e.g. keep-alive, close
  • http_method: HTTP method e.g. GET, POST OPTIONS
  • request_scheme: URL scheme (http or https).
  • http_status: HTTP status code e.g. 200, 301, 404
  • dest_ip: Destination host IP
  • dest_port: Destination host port
  • url: URL requested
  • url_path: URL path requested
  • content_type: indicates the media type of the entity-body
  • mimetype: similar to content type but without parameters e.g. if the content type is text/HTML; charset=utf-8 the mimetype would be 'text/html'.
  • url_query: raw URL query string
  • cookies: A dictionary with the contents of all cookies transmitted with the request.
  • data: Contains the incoming request data as string in case it came with a mimetype Werkzeug does not handle.
  • content_md5: MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body.
  • referrer: URL referrer
  • authorisation: HTTP basic/digest authorization header
  • duration - Request duration from the time the request was received to the time the request was replied to
  • request_id: Correlates HTTP requests between the client and server.
  • user(remote_user): If the server supports user authentication, and the script is protected, this attribute contains the username the user has authenticated as.

Flask-Web-Log can log requests to the following formats:

  • CSV
  • JSON
  • SQLITE DB
  • STDOUT

Installation

You can install Flask-Web-Log using pip:

pip install flask_web_log

or directly from source:

git clone git@github.com:nethunters/flask-web-log.git
cd flask-web-log
python setup.py install

Quickstart

Import flask_web_log and initialise.

from flask_web_log import Log
Log(app)

Example App

from flask import Flask, request, Response
from flask_web_log import Log

app = Flask(__name__)
app.config["LOG_TYPE"] = "CSV"
Log(app)


@app.route('/', methods=["GET", "POST"])
def hello():
    return "lets test this log!"


if __name__ == '__main__':
    app.run(debug=True)

Configuration

The following configuration values are used by Flask-Web-Log:

Config Value Description
LOG_TYPE Format to log out to. Currently supported log formats are: CSV, JSON, STDOUT and SQLITE DB. Defaults to CSV.
LOG_FILENAME The filename, without the file extension, for the log. Defaults to flask-web-log.
LOG_LOCATION The directory to log to. Defaults to the current directory.

License

Flask-Web-Log is licensed under the Apache2.0 license. See License.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

Flask-Web-Log-0.1.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file Flask-Web-Log-0.1.tar.gz.

File metadata

  • Download URL: Flask-Web-Log-0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for Flask-Web-Log-0.1.tar.gz
Algorithm Hash digest
SHA256 af57fdbb1d95111110d797660baf8fa15f2a2d2e409b521840998892cd438fc5
MD5 483394fd5aedd217791fbd8bc4d93870
BLAKE2b-256 750cfdf82cfa6734834356785ebe0a46287e6cf9c883230395731a24d8287297

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