Can I print a detailed request log? #5592

Closed
opened 2026-02-21 18:11:47 -05:00 by yindo · 3 comments
Owner

Originally created by @liutao-python on GitHub (Sep 13, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

It is hoped that the request log can be printed in the service, including the request view function, request method and other information. When the request ends, printing takes time.

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @liutao-python on GitHub (Sep 13, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. It is hoped that the request log can be printed in the service, including the request view function, request method and other information. When the request ends, printing takes time. ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [ ] I am interested in contributing to this feature.
yindo added the 💪 enhancement label 2026-02-21 18:11:47 -05:00
yindo closed this issue 2026-02-21 18:11:47 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 13, 2024):

Hello @liutao-python! I'm here to help you with any bugs, questions, or contributions you might have. I'm an expert in software development and technical support and I'm looking forward to assisting you.

Yes, you can print a detailed request log in the Dify service. You can extend the existing after_request function in the api/app.py file to log the request details, including the request view function, request method, and other information. Here is an example of how you can modify the after_request function to include detailed logging:

import logging
from flask import request

@app.after_request
def after_request(response):
    """Add Version headers to the response and log request details."""
    response.set_cookie("remember_token", "", expires=0)
    response.headers.add("X-Version", app.config["CURRENT_VERSION"])
    response.headers.add("X-Env", app.config["DEPLOY_ENV"])

    # Log request details
    logging.info(f"Request Method: {request.method}")
    logging.info(f"Request Path: {request.path}")
    logging.info(f"Request Args: {request.args}")
    logging.info(f"Request Form: {request.form}")
    logging.info(f"Request JSON: {request.json}")
    logging.info(f"Response Status: {response.status}")
    logging.info(f"Response Time: {response.elapsed.total_seconds()} seconds")

    return response

This will log the request method, path, arguments, form data, JSON payload, response status, and response time after each request is processed.

Additionally, ensure that your logging configuration is set up to capture these logs. You can adjust the verbosity or detail level of the logs in the opensearch_dashboards.yml file:

logging.verbose: true

This setting will log all events, including system usage information and all requests [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 13, 2024): <!-- Greeting --> Hello @liutao-python! I'm here to help you with any bugs, questions, or contributions you might have. I'm an expert in software development and technical support and I'm looking forward to assisting you. <!-- Answer --> Yes, you can print a detailed request log in the Dify service. You can extend the existing `after_request` function in the `api/app.py` file to log the request details, including the request view function, request method, and other information. Here is an example of how you can modify the `after_request` function to include detailed logging: ```python import logging from flask import request @app.after_request def after_request(response): """Add Version headers to the response and log request details.""" response.set_cookie("remember_token", "", expires=0) response.headers.add("X-Version", app.config["CURRENT_VERSION"]) response.headers.add("X-Env", app.config["DEPLOY_ENV"]) # Log request details logging.info(f"Request Method: {request.method}") logging.info(f"Request Path: {request.path}") logging.info(f"Request Args: {request.args}") logging.info(f"Request Form: {request.form}") logging.info(f"Request JSON: {request.json}") logging.info(f"Response Status: {response.status}") logging.info(f"Response Time: {response.elapsed.total_seconds()} seconds") return response ``` This will log the request method, path, arguments, form data, JSON payload, response status, and response time after each request is processed. Additionally, ensure that your logging configuration is set up to capture these logs. You can adjust the verbosity or detail level of the logs in the `opensearch_dashboards.yml` file: ```yml logging.verbose: true ``` This setting will log all events, including system usage information and all requests <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/volumes/opensearch/opensearch_dashboards.yml)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@liutao-python commented on GitHub (Sep 13, 2024):

Yes, I know it can be extended, but I would prefer to have these things built into the project, I think it is a basic function of a service

@liutao-python commented on GitHub (Sep 13, 2024): Yes, I know it can be extended, but I would prefer to have these things built into the project, I think it is a basic function of a service
Author
Owner

@crazywoola commented on GitHub (Sep 13, 2024):

Please open a issue here https://github.com/langgenius/dify-sandbox instead.

@crazywoola commented on GitHub (Sep 13, 2024): Please open a issue here https://github.com/langgenius/dify-sandbox instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5592