Skip to content

Commit

Permalink
Modified logging module name to avoid clash with stdlib (#1426)
Browse files Browse the repository at this point in the history
* Modified logging module name to avoid clash with stdlib

* Renamed _logging to indicate privacy
  • Loading branch information
euri10 committed Mar 28, 2022
1 parent 295664e commit b48d32d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ files =
uvicorn/middleware/wsgi.py,
tests/middleware/test_wsgi.py,
uvicorn/supervisors/watchgodreload.py,
uvicorn/logging.py,
uvicorn/_logging.py,
uvicorn/middleware/asgi2.py,
uvicorn/server.py,
uvicorn/__init__.py,
Expand Down
2 changes: 1 addition & 1 deletion tests/middleware/test_message_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from tests.middleware.test_logging import caplog_for_logger
from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL
from uvicorn.middleware.message_logger import MessageLoggerMiddleware


Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from typing import Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL

if sys.version_info < (3, 8): # pragma: py-gte-38
from typing_extensions import Literal
Expand Down Expand Up @@ -82,12 +82,12 @@
"disable_existing_loggers": False,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"()": "uvicorn._logging.DefaultFormatter",
"fmt": "%(levelprefix)s %(message)s",
"use_colors": None,
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"()": "uvicorn._logging.AccessFormatter",
"fmt": '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s', # noqa: E501
},
},
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/middleware/message_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
WWWScope,
)

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL

PLACEHOLDER_FORMAT = {
"body": "<{length} bytes>",
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/protocols/http/h11_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import h11

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL
from uvicorn.protocols.http.flow_control import (
CLOSE_HEADER,
HIGH_WATER_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/protocols/http/httptools_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import httptools

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL
from uvicorn.protocols.http.flow_control import (
CLOSE_HEADER,
HIGH_WATER_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/protocols/websockets/websockets_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import websockets
from websockets.extensions.permessage_deflate import ServerPerMessageDeflateFactory

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL
from uvicorn.protocols.utils import get_local_addr, get_remote_addr, is_ssl


Expand Down
2 changes: 1 addition & 1 deletion uvicorn/protocols/websockets/wsproto_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from wsproto.extensions import PerMessageDeflate
from wsproto.utilities import RemoteProtocolError

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn._logging import TRACE_LOG_LEVEL
from uvicorn.protocols.utils import get_local_addr, get_remote_addr, is_ssl


Expand Down

6 comments on commit b48d32d

@jsolis88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks custom logging when using default formatters in uvicorn.logging.

@Kludex
Copy link
Member

@Kludex Kludex commented on b48d32d Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks custom logging when using default formatters in uvicorn.logging.

@euri10 Should we revert it?

@Kludex
Copy link
Member

@Kludex Kludex commented on b48d32d Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show an example? @jsolis88

@jsolis88
Copy link

@jsolis88 jsolis88 commented on b48d32d Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplest example, that we are currently using:

{
    "version": 1,
    "disable_existing_loggers": false,
    "formatters": {
        "access": {
            "()": "uvicorn.logging.AccessFormatter",
            "fmt": "%(asctime)s - %(name)s - %(levelprefix)s - %(process)d - %(client_addr)s - %(request_line)s - %(status_code)s"
        },
	"minimum": {
            "()": "uvicorn.logging.AccessFormatter",
            "fmt": "%(asctime)s - %(client_addr)s - %(request_line)s - %(status_code)s",
            "use_colors": false
        }
    },
    "handlers": {
        "critical": {
			"formatter": "access",
                        "class": "logging.StreamHandler",
			"stream": "ext://sys.stderr",
			"level": "ERROR"
		},
	"info": {
			"formatter": "minimum",
			"class": "logging.StreamHandler",
			"stream": "ext://sys.stdout",
                        "level": "INFO"
		}
    },
    "loggers": {
        "uvicorn.access": {
            "handlers": [
                "critical"
            ],
            "level": "ERROR"
        },
        "app": {
            "handlers": [
                "info"
            ],
            "level": "INFO"
        }
    }
}

And running uvicorn using --log-config <path/to/file>.

I think this will also have impact in custom formatters that inherits from AccessFormatter and DefaultFormatter.

This is also partly our fault, because we didn't freeze the version of uvicorn in the requirements.txt file used to build docker images.

@Kludex
Copy link
Member

@Kludex Kludex commented on b48d32d Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would expect users to use that configuration file...

@Kludex
Copy link
Member

@Kludex Kludex commented on b48d32d Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #1543 to discuss it. Thanks for reporting it. 🙏

Please sign in to comment.