Skip to content

Commit bb9460d

Browse files
authored
Unify uvicorn and backend logging (#4034)
## What type of PR is this? (check all applicable) - [ X] Feature ## Have you discussed this change with the InvokeAI team? - [ X] Yes ## Have you updated all relevant documentation? - [ X] Yes - this makes invokeai behave the way it is described in LOGGING.md ## Description Prior to this PR, the uvicorn embedded web server did all its logging independently of the InvokeAI logging infrastructure, and none of the command-line or `invokeai.yaml` configuration directives, such as `log_level` had any effect on its output. This PR replaces the uvicorn logger with InvokeAI's, simultaneously creating a more uniform output experience, as well as a unified way to control the amount and destination of the logs. Here's what we used to see at startup: ``` [2023-07-27 07:29:48,027]::[InvokeAI]::INFO --> InvokeAI version 3.0.1rc2 [2023-07-27 07:29:48,027]::[InvokeAI]::INFO --> Root directory = /home/lstein/invokeai-main [2023-07-27 07:29:48,028]::[InvokeAI]::INFO --> GPU device = cuda NVIDIA GeForce RTX 4070 [2023-07-27 07:29:48,040]::[InvokeAI]::INFO --> Scanning /home/lstein/invokeai-main/models for new models [2023-07-27 07:29:49,263]::[InvokeAI]::INFO --> Scanned 22 files and directories, imported 10 models [2023-07-27 07:29:49,271]::[InvokeAI]::INFO --> Model manager service initialized INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit) INFO: 127.0.0.1:44404 - "GET /socket.io/?EIO=4&transport=polling&t=OcN7Pvd HTTP/1.1" 200 OK INFO: 127.0.0.1:44404 - "POST /socket.io/?EIO=4&transport=polling&t=OcN7Pw6&sid=SB-NsBKLSrW7YtM0AAAA HTTP/1.1" 200 OK INFO: ('127.0.0.1', 44418) - "WebSocket /socket.io/?EIO=4&transport=websocket&sid=SB-NsBKLSrW7YtM0AAAA" [accepted] INFO: connection open INFO: 127.0.0.1:44430 - "GET /socket.io/?EIO=4&transport=polling&t=OcN7Pw9&sid=SB-NsBKLSrW7YtM0AAAA HTTP/1.1" 200 OK INFO: 127.0.0.1:44404 - "GET /socket.io/?EIO=4&transport=polling&t=OcN7PwU&sid=SB-NsBKLSrW7YtM0AAAA HTTP/1.1" 200 OK INFO: 127.0.0.1:44404 - "GET /api/v1/images/?is_intermediate=true HTTP/1.1" 200 OK INFO: 127.0.0.1:43448 - "GET / HTTP/1.1" 200 OK INFO: connection closed INFO: 127.0.0.1:43448 - "GET /assets/index-5a784cdd.js HTTP/1.1" 200 OK INFO: 127.0.0.1:43458 - "GET /assets/favicon-0d253ced.ico HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:43448 - "GET /locales/en.json HTTP/1.1" 200 OK ``` And here's what we see with the new implementation: ``` [2023-07-27 12:05:28,810]::[uvicorn.error]::INFO --> Started server process [875161] [2023-07-27 12:05:28,810]::[uvicorn.error]::INFO --> Waiting for application startup. [2023-07-27 12:05:28,810]::[InvokeAI]::INFO --> InvokeAI version 3.0.1rc2 [2023-07-27 12:05:28,810]::[InvokeAI]::INFO --> Root directory = /home/lstein/invokeai-main [2023-07-27 12:05:28,811]::[InvokeAI]::INFO --> GPU device = cuda NVIDIA GeForce RTX 4070 [2023-07-27 12:05:28,823]::[InvokeAI]::INFO --> Scanning /home/lstein/invokeai-main/models for new models [2023-07-27 12:05:29,970]::[InvokeAI]::INFO --> Scanned 22 files and directories, imported 10 models [2023-07-27 12:05:29,977]::[InvokeAI]::INFO --> Model manager service initialized [2023-07-27 12:05:29,980]::[uvicorn.error]::INFO --> Application startup complete. [2023-07-27 12:05:29,981]::[uvicorn.error]::INFO --> Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit) [2023-07-27 12:05:32,140]::[uvicorn.access]::INFO --> 127.0.0.1:45236 - "GET /socket.io/?EIO=4&transport=polling&t=OcO6ILb HTTP/1.1" 200 [2023-07-27 12:05:32,142]::[uvicorn.access]::INFO --> 127.0.0.1:45248 - "GET /socket.io/?EIO=4&transport=polling&t=OcO6ILb HTTP/1.1" 200 [2023-07-27 12:05:32,154]::[uvicorn.access]::INFO --> 127.0.0.1:45236 - "POST /socket.io/?EIO=4&transport=polling&t=OcO6ILr&sid=13O4-5uLx5eP-NuqAAAA HTTP/1.1" 200 [2023-07-27 12:05:32,168]::[uvicorn.access]::INFO --> 127.0.0.1:45252 - "POST /socket.io/?EIO=4&transport=polling&t=OcO6IM0&sid=0KRqxmh7JLc8t7wZAAAB HTTP/1.1" 200 [2023-07-27 12:05:32,171]::[uvicorn.error]::INFO --> ('127.0.0.1', 45264) - "WebSocket /socket.io/?EIO=4&transport=websocket&sid=0KRqxmh7JLc8t7wZAAAB" [accepted] [2023-07-27 12:05:32,172]::[uvicorn.error]::INFO --> connection open [2023-07-27 12:05:32,174]::[uvicorn.access]::INFO --> 127.0.0.1:45276 - "GET /socket.io/?EIO=4&transport=polling&t=OcO6IM3&sid=0KRqxmh7JLc8t7wZAAAB HTTP/1.1" 200 ``` You can also divert everything to a file with a `invokeai.yaml` entry like this: ``` Logging: log_handlers: - file=/home/lstein/invokeai/logs/access_log log_format: plain log_level: info ``` This works with syslog and other log handlers as well.
2 parents 53028fe + 2bb4e6d commit bb9460d

File tree

9 files changed

+46
-26
lines changed

9 files changed

+46
-26
lines changed

invokeai/app/api_app.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from inspect import signature
55

6+
import logging
67
import uvicorn
78
import socket
89

@@ -210,11 +211,25 @@ def find_port(port: int):
210211
port = find_port(app_config.port)
211212
if port != app_config.port:
212213
logger.warn(f"Port {app_config.port} in use, using port {port}")
214+
213215
# Start our own event loop for eventing usage
214216
loop = asyncio.new_event_loop()
215-
config = uvicorn.Config(app=app, host=app_config.host, port=port, loop=loop)
216-
# Use access_log to turn off logging
217+
config = uvicorn.Config(
218+
app=app,
219+
host=app_config.host,
220+
port=port,
221+
loop=loop,
222+
log_level=app_config.log_level,
223+
)
217224
server = uvicorn.Server(config)
225+
226+
# replace uvicorn's loggers with InvokeAI's for consistent appearance
227+
for logname in ["uvicorn.access", "uvicorn"]:
228+
l = logging.getLogger(logname)
229+
l.handlers.clear()
230+
for ch in logger.handlers:
231+
l.addHandler(ch)
232+
218233
loop.run_until_complete(server.serve())
219234

220235

invokeai/frontend/web/dist/assets/App-69e5ea36.js renamed to invokeai/frontend/web/dist/assets/App-58b095d3.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

invokeai/frontend/web/dist/assets/MantineProvider-8184f020.js renamed to invokeai/frontend/web/dist/assets/MantineProvider-ea42d3d1.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

invokeai/frontend/web/dist/assets/ThemeLocaleProvider-9ac72450.js renamed to invokeai/frontend/web/dist/assets/ThemeLocaleProvider-13e3db3d.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

invokeai/frontend/web/dist/assets/index-89941396.js renamed to invokeai/frontend/web/dist/assets/index-5a784cdd.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

invokeai/frontend/web/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
margin: 0;
1313
}
1414
</style>
15-
<script type="module" crossorigin src="./assets/index-89941396.js"></script>
15+
<script type="module" crossorigin src="./assets/index-5a784cdd.js"></script>
1616
</head>
1717

1818
<body dir="ltr">

invokeai/frontend/web/src/services/api/schema.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,12 +5562,6 @@ export type components = {
55625562
* @enum {string}
55635563
*/
55645564
StableDiffusion2ModelFormat: "checkpoint" | "diffusers";
5565-
/**
5566-
* StableDiffusion1ModelFormat
5567-
* @description An enumeration.
5568-
* @enum {string}
5569-
*/
5570-
StableDiffusion1ModelFormat: "checkpoint" | "diffusers";
55715565
/**
55725566
* StableDiffusionXLModelFormat
55735567
* @description An enumeration.
@@ -5580,6 +5574,12 @@ export type components = {
55805574
* @enum {string}
55815575
*/
55825576
ControlNetModelFormat: "checkpoint" | "diffusers";
5577+
/**
5578+
* StableDiffusion1ModelFormat
5579+
* @description An enumeration.
5580+
* @enum {string}
5581+
*/
5582+
StableDiffusion1ModelFormat: "checkpoint" | "diffusers";
55835583
};
55845584
responses: never;
55855585
parameters: never;

invokeai/frontend/web/src/services/api/types.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ export type ControlField = components['schemas']['ControlField'];
4242
// Model Configs
4343
export type LoRAModelConfig = components['schemas']['LoRAModelConfig'];
4444
export type VaeModelConfig = components['schemas']['VaeModelConfig'];
45+
export type ControlNetModelCheckpointConfig =
46+
components['schemas']['ControlNetModelCheckpointConfig'];
47+
export type ControlNetModelDiffusersConfig =
48+
components['schemas']['ControlNetModelDiffusersConfig'];
4549
export type ControlNetModelConfig =
46-
components['schemas']['ControlNetModelConfig'];
50+
| ControlNetModelCheckpointConfig
51+
| ControlNetModelDiffusersConfig;
4752
export type TextualInversionModelConfig =
4853
components['schemas']['TextualInversionModelConfig'];
4954
export type DiffusersModelConfig =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.1rc1"
1+
__version__ = "3.0.1rc2"

0 commit comments

Comments
 (0)