Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #236
Closed
Open
Issue created Jun 06, 2018 by Administrator@rootContributor

[Python] Swagger API Clients will log to stderr by default

Created by: asqui

Hello,

I am using the OpsGenie SDK, which is autogenerated using Swagger, and was most surprised to find printing urlib3 retry notices out to stderr in my application.

The culprit appears to be the default behaviour of configuring a stderr StreamHandler here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/configuration.mustache#L133

This is in contradiction to the guidance in the Python logging docs: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

Most notably, these docs say:

If the using application does not use logging, and library code makes logging calls, then (as described in the previous section) events of severity WARNING and greater will be printed to sys.stderr. This is regarded as the best default behaviour.

So if the Swagger template did not set up this StreamHandler, the default behaviour for an application that does not configure logging would be the same.

Instead, what is happening now is that this StreamHandler interferes with applications that do configure the desired logging handlers, and causes duplicate warnings to be logged to stderr, in addition to the ones that are being captured by the other handlers configured by the application.

Also from the Python logging docs linked above:

Note It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements

To make this a bit more concrete, in our application we never expect any output to stderr, and as a fallback we capture any and email it. An unintended consequence of adopting a Swagger-generated API is that now the application has started generating stderr under certain circumstances, which is both surprising and undesirable.

Hope that makes sense? Keen to hear thoughts...

Assignee
Assign to
Time tracking