Code Monkey home page Code Monkey logo

logging_demo's Introduction

Logging Demo

Simple FastAPI app which logs incoming post requests.

The app returns HTTP code 202 'Accepted' and uses FastAPI's BackgroundTasks to asynchronously log the payload to the given file.

log_router took 0.000084 seconds to execute.
async_log took 0.003367 seconds to execute.

This speeds up performance as well as decoupling response times from the size of the logged payload.

Setup

Follow these steps to set up the project:

  1. Install dependencies:
    pip install -r requirements.txt
  2. Run the application:
    python app.py

After setting up, you can visit the /docs endpoint in your web browser to view the Swagger documentation for the API.

API Documentation

This application exposes a single API endpoint /v1/log which accepts POST requests.

POST /v1/log

This endpoint is used to log messages. The request body should be a JSON object with the following properties:

  • file_name: The name of the log file to write to. It should be a string of maximum 20 characters, and should match the pattern ^[a-zA-Z0-9_-]+\\.log$. For example: "mylogfile.log".
  • level: The level of the log message. It should be a string that matches the pattern ^(debug|info|warning|error|critical)$. For example: "info".
  • context: The context of the log message. It should be a string of maximum 20 characters. For example: "foo".
  • message: The log message. It should be a string of maximum 1000 characters. For example: "This is a log message".

All properties are required.

The endpoint responds with a status code of 202 if the log message was successfully processed. In case of a validation error, it responds with a status code of 422 and a JSON object describing the validation errors.

logging_demo's People

Contributors

stephaneglaugier avatar

Stargazers

 avatar

Watchers

 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.