OpenAPITools / OpenAPITools/openapi-generator

[BUG] Difficulty Redirecting Default Loggers to File in Generated Python Client

Open
#5,701 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I've generated a Python client with no errors based on a valid Open API specification as follows:

openapi-generator generate \
  -i <open_api_spec.yaml>
  -g python
  --package-name <package_name>

I've then locally installed the package with pip install . to validate a proof-of-concept project.

I am attempting to redirect DEBUG output from the built-in package_logger and urllib3_logger to one consolidated file for the proof-of-concept — the goal is to be able to see the specific HTTP requests the Python client makes in a single logfile to help debug any errors.

I have the following Configuration object created and set for the Python client:

from <package_name> import Configuration
from <package_name> import ApiClient
from <package_name> import <apis_and_models>

client_config = Configuration(
    host=<host>
)

client_config.verify_ssl = False
client_config.debug = True
client_config.logger_file = <local_specified_logfile.log>

with ApiClient(
    configuration=client_config
) as api_client:

    # Successful usage of imported APIs and Models

I also used from logging_tree import printout to see the logger hierarchy:

<--""
   Level WARNING
   Handler Stream <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>
     Formatter fmt='%(levelname)s:%(name)s:%(message)s' datefmt=None
   |
   o<--"package_name"
   |   Level DEBUG
   |   Handler File 'local_specified_logfile.log'
   |     Formatter fmt='%(asctime)s %(levelname)s %(message)s' datefmt=None
   |   |
   |   o<--"package_name.rest"
   |       Level NOTSET so inherits level DEBUG
   |
   o<--"urllib3"
       Level DEBUG
       Handler <NullHandler (NOTSET)>
       Handler File 'local_specified_logfile.log'
         Formatter fmt='%(asctime)s %(levelname)s %(message)s' datefmt=None
       |
       o<--"urllib3.connection"
       |   Level NOTSET so inherits level DEBUG
       |
       o<--"urllib3.connectionpool"
       |   Level NOTSET so inherits level DEBUG
       |
       o<--"urllib3.poolmanager"
       |   Level NOTSET so inherits level DEBUG
       |
       o<--"urllib3.response"
       |   Level NOTSET so inherits level DEBUG
       |
       o<--[urllib3.util]
           |
           o<--"urllib3.util.retry"
               Level NOTSET so inherits level DEBUG

I can see where the local_specified_logfile.log is created in the expected location, but the file has no content after running the Python client.

I'm new to the openapi-generator and am not sure if this is a bug or if I need some assistance on how to set this up properly — I wasn't able to find an answer after searching the OpenAPI Generator docs, GitHub, and Stack Overflow, so decided to reach out here. Thank you in advance for your time and help!

openapi-generator version
Component Version
OpenAPI Generator 4.2.3
Python 3.8.1
Java Version 8 Update 241
macOS 10.15.3
Command line used for generation
openapi-generator generate \
  -i <open_api_spec.yaml>
  -g python
  --package-name <package_name>
Steps to reproduce

See Description section.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the generated Python client with the shown openapi-generator command, then inspect the generated Configuration and ApiClient logging setup, including package_logger and urllib3_logger. Confirm the behavior with client_config.debug and client_config.logger_file enabled; done means DEBUG HTTP output from both loggers appears in the specified consolidated logfile.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.