Skip to main content

Flask endpoint delivering filtered log messages via REST

Project description

PBU Log Inspector

Flask (pip) and React (npm) integration for python-basic-utils logs.

Installation

pip3 install pbu-log-inspector
npm install pbu-log-inspector

Integration

Backend

from flask import Flask
from loginspect import register_endpoint

app = Flask(__name__)
register_endpoint(app)
app.run(host="0.0.0.0", port=5444)

The register_endpoint function will register an endpoint GET /api/_logs, which will can be used to serve daily logs. There are additional parameters available for this function:

register_endpoint(app, log_folder="_logs", api_prefix="/api", log_file_mapping=None, login_check=None)
  • The default log_folder is relative to the start script of your application, since that is the pbu default.
  • If you provide a different api_prefix this will just be the prefix, not the /_logs part. E.g. /rest would result in an endpoint /rest/_logs
  • The log_file_mapping is optional and only necessary, if you instructed pbu to write to different file names than the defaults. When provided, the mapping needs to provide a dictionary with keys representing the default pbu log file names (info.log, debug.log, warning.log, error.log) and their respective values are the name of the log file in your app.
  • If your application includes authentication, provide a function via the login_check parameter that performs the authentication. No parameters are passed to the function. You can use from flask import request and access all request data

Restrictions

  • The date needs to be the first part of a log message
  • The date needs to be in the format %Y-%m-%d %H:%M:%S.%s, e.g. 2019-12-25 13:37:01.567
  • There is no limit on how many logs the endpoint delivers. This can easily cause large payloads and potentially exceed operational limits (e.g. browser performance, response size, ...)

Frontend

import React from "react"
import LogInspectorContainer from "pbu-log-inspector"

const MyContainer = props => (
    <div>
        <LogInspectorContainer />
    </div>
)

The container provides the following properties:

  • apiPrefix - default "/api" - corresponds to the api_prefix parameter configured on the Flask backend
  • applyRequestOptions - default null - a function that takes the base request parameters and has to return the parameters for the fetch request, in case authentication is required and headers need to be set
  • errorHandler - default null - a function to handle an error during fetching logs (e.g. show an alert), no return is expected. The parameter is the error thrown.

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

pbu-log-inspector-0.0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

pbu_log_inspector-0.0.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pbu-log-inspector-0.0.2.tar.gz.

File metadata

  • Download URL: pbu-log-inspector-0.0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for pbu-log-inspector-0.0.2.tar.gz
Algorithm Hash digest
SHA256 928d98bc9f6b3ed3836e41b0cb2b3ba6c53f2199e29f8010a6a0b692eff69f63
MD5 5175e453e61a3b4345446e19062c958f
BLAKE2b-256 182e56532a9ffac6d6f57458cced1c569e73ccef7329168173e3fbd8e92f68ad

See more details on using hashes here.

File details

Details for the file pbu_log_inspector-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pbu_log_inspector-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for pbu_log_inspector-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05433a12f9520444479b3d46c93b77e8e9d0b05b1b9ef9f251dd722e911bd4fd
MD5 e772516a605e8027bc03063dcab72efa
BLAKE2b-256 280deaaf631f9f1df8c6e8c6c82d8770037cee2a56dd27966f77f291011e2f59

See more details on using hashes here.

Supported by

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