npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pbu-log-inspector

v0.0.6

Published

React components for fetching and displaying logs from a Flask backend using the pbu-log-inspector pip package

Downloads

3

Readme

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.