Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
974201c8
Unverified
Commit
974201c8
authored
Apr 28, 2025
by
ishandhanani
Committed by
GitHub
Apr 28, 2025
Browse files
refactor: move logging config to runtime (#863)
parent
566068dc
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
104 additions
and
124 deletions
+104
-124
components/planner/src/dynamo/planner/circusd.py
components/planner/src/dynamo/planner/circusd.py
+2
-2
components/planner/src/dynamo/planner/local_connector.py
components/planner/src/dynamo/planner/local_connector.py
+2
-2
deploy/dynamo/sdk/src/dynamo/sdk/cli/deployment.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/deployment.py
+2
-2
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
+2
-3
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve_dynamo.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve_dynamo.py
+2
-2
deploy/dynamo/sdk/src/dynamo/sdk/cli/serving.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/serving.py
+2
-2
deploy/dynamo/sdk/src/dynamo/sdk/cli/utils.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/utils.py
+2
-2
deploy/dynamo/sdk/src/dynamo/sdk/lib/logging.py
deploy/dynamo/sdk/src/dynamo/sdk/lib/logging.py
+0
-105
examples/hello_world/hello_world.py
examples/hello_world/hello_world.py
+2
-2
examples/llm/components/planner.py
examples/llm/components/planner.py
+2
-2
lib/bindings/python/src/dynamo/runtime/logging.py
lib/bindings/python/src/dynamo/runtime/logging.py
+86
-0
No files found.
components/planner/src/dynamo/planner/circusd.py
View file @
974201c8
...
...
@@ -23,9 +23,9 @@ from typing import Any, Dict, List, Optional
from
circus.client
import
CircusClient
from
circus.exc
import
CallError
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
configure_
server
_logging
()
configure_
dynamo
_logging
()
logger
=
logging
.
getLogger
(
__name__
)
...
...
components/planner/src/dynamo/planner/local_connector.py
View file @
974201c8
...
...
@@ -25,9 +25,9 @@ import filelock
from
dynamo.planner.circusd
import
CircusController
from
dynamo.planner.planner_connector
import
PlannerConnector
from
dynamo.runtime
import
DistributedRuntime
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
configure_
server
_logging
()
configure_
dynamo
_logging
()
logger
=
logging
.
getLogger
(
__name__
)
...
...
deploy/dynamo/sdk/src/dynamo/sdk/cli/deployment.py
View file @
974201c8
...
...
@@ -35,14 +35,14 @@ from bentoml.exceptions import BentoMLException, CLIException, CloudRESTApiClien
from
rich.console
import
Console
from
simple_di
import
Provide
,
inject
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
from
.utils
import
resolve_service_config
# Configure logging to suppress INFO HTTP logs
logging
.
getLogger
(
"httpx"
).
setLevel
(
logging
.
WARNING
)
# HTTP client library logs
logging
.
getLogger
(
"httpcore"
).
setLevel
(
logging
.
WARNING
)
# HTTP core library logs
configure_
server
_logging
()
configure_
dynamo
_logging
()
logger
=
logging
.
getLogger
(
__name__
)
...
...
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
View file @
974201c8
...
...
@@ -91,9 +91,8 @@ def serve(
Starts a local server for the specified Dynamo pipeline.
"""
# Warn
ing
:
i
nternal
from
dynamo.runtime.logg
ing
i
mport
configure_dynamo_logging
from
dynamo.sdk.lib.loader
import
find_and_load_service
from
dynamo.sdk.lib.logging
import
configure_server_logging
from
dynamo.sdk.lib.service
import
LinkedServices
# Extract extra arguments not captured by typer
...
...
@@ -119,7 +118,7 @@ def serve(
console
.
print
(
f
"DYNAMO_SERVICE_CONFIG=
{
json
.
dumps
(
service_configs
)
}
"
)
raise
typer
.
Exit
()
configure_
server
_logging
()
configure_
dynamo
_logging
()
if
service_configs
:
logger
.
info
(
f
"Running dynamo serve with service configs
{
service_configs
}
"
)
...
...
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve_dynamo.py
View file @
974201c8
...
...
@@ -146,7 +146,7 @@ def main(
from
bentoml._internal.container
import
BentoMLContainer
from
bentoml._internal.context
import
server_context
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
# Setup signal handlers for graceful shutdown
setup_signal_handlers
()
...
...
@@ -172,7 +172,7 @@ def main(
if
service_name
and
service_name
!=
service
.
name
:
service
=
service
.
find_dependent_by_name
(
service_name
)
configure_
server
_logging
(
service_name
=
service_name
,
worker_id
=
worker_id
)
configure_
dynamo
_logging
(
service_name
=
service_name
,
worker_id
=
worker_id
)
if
runner_map
:
BentoMLContainer
.
remote_runner_mapping
.
set
(
t
.
cast
(
t
.
Dict
[
str
,
str
],
json
.
loads
(
runner_map
))
...
...
deploy/dynamo/sdk/src/dynamo/sdk/cli/serving.py
View file @
974201c8
...
...
@@ -131,13 +131,13 @@ def serve_dynamo_graph(
service_name
:
str
=
""
,
enable_local_planner
:
bool
=
False
,
)
->
CircusRunner
:
from
dynamo.runtime.logging
import
configure_dynamo_logging
from
dynamo.sdk.cli.circus
import
create_arbiter
,
create_circus_watcher
from
dynamo.sdk.lib.loader
import
find_and_load_service
from
dynamo.sdk.lib.logging
import
configure_server_logging
from
.allocator
import
ResourceAllocator
configure_
server
_logging
(
service_name
=
service_name
)
configure_
dynamo
_logging
(
service_name
=
service_name
)
bento_id
:
str
=
""
namespace
:
str
=
""
...
...
deploy/dynamo/sdk/src/dynamo/sdk/cli/utils.py
View file @
974201c8
...
...
@@ -31,9 +31,9 @@ import click
import
yaml
from
click
import
Command
,
Context
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
configure_
server
_logging
()
configure_
dynamo
_logging
()
logger
=
logging
.
getLogger
(
__name__
)
...
...
deploy/dynamo/sdk/src/dynamo/sdk/lib/logging.py
deleted
100644 → 0
View file @
566068dc
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
json
import
logging
import
logging.config
import
os
import
tempfile
from
dynamo.runtime.logging
import
configure_logger
as
configure_dynamo_logger
def
configure_server_logging
(
service_name
:
str
|
None
=
None
,
worker_id
:
int
|
None
=
None
):
"""
A single place to configure logging for Dynamo.
"""
# First, remove any existing handlers to avoid duplication
root_logger
=
logging
.
getLogger
()
for
handler
in
root_logger
.
handlers
[:]:
root_logger
.
removeHandler
(
handler
)
# Configure the logger with Dynamo's handler
configure_dynamo_logger
(
service_name
,
worker_id
)
# map the DYN_LOG variable to a logging level
dyn_var
=
os
.
environ
.
get
(
"DYN_LOG"
,
"info"
)
dyn_level
=
log_level_mapping
(
dyn_var
)
configure_vllm_logging
(
dyn_level
)
# loggers that should be configured to ERROR
error_loggers
=
[
"bentoml"
,
"tag"
]
for
logger_name
in
error_loggers
:
logger
=
logging
.
getLogger
(
logger_name
)
logger
.
handlers
=
[]
logger
.
setLevel
(
logging
.
ERROR
)
logger
.
propagate
=
True
def
log_level_mapping
(
level
:
str
)
->
int
:
"""
The DYN_LOG variable is set using "debug" or "trace" or "info.
This function maps those to the appropriate logging level and defaults to INFO
if the variable is not set or a bad value.
"""
if
level
==
"debug"
:
return
logging
.
DEBUG
elif
level
==
"info"
:
return
logging
.
INFO
elif
level
==
"warn"
or
level
==
"warning"
:
return
logging
.
WARNING
elif
level
==
"error"
:
return
logging
.
ERROR
elif
level
==
"critical"
:
return
logging
.
CRITICAL
elif
level
==
"trace"
:
return
logging
.
INFO
else
:
return
logging
.
INFO
def
configure_vllm_logging
(
dyn_level
:
int
):
"""
vLLM requires a logging config file to be set in the environment.
This function creates a temporary file with the VLLM logging config and sets the
VLLM_LOGGING_CONFIG_PATH environment variable to the path of the file.
"""
os
.
environ
[
"VLLM_CONFIGURE_LOGGING"
]
=
"1"
vllm_level
=
logging
.
getLevelName
(
dyn_level
)
# Create a temporary config file for VLLM
vllm_config
=
{
"formatters"
:
{
"simple"
:
{
"format"
:
"%(message)s"
}},
"handlers"
:
{
"dynamo"
:
{
"class"
:
"dynamo.runtime.logging.LogHandler"
,
"formatter"
:
"simple"
,
"level"
:
vllm_level
,
}
},
"loggers"
:
{
"vllm"
:
{
"handlers"
:
[
"dynamo"
],
"level"
:
vllm_level
,
"propagate"
:
False
}
},
"version"
:
1
,
"disable_existing_loggers"
:
False
,
}
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
suffix
=
".json"
,
delete
=
False
)
as
f
:
json
.
dump
(
vllm_config
,
f
)
os
.
environ
[
"VLLM_LOGGING_CONFIG_PATH"
]
=
f
.
name
examples/hello_world/hello_world.py
View file @
974201c8
...
...
@@ -19,9 +19,9 @@ from fastapi import FastAPI
from
fastapi.responses
import
StreamingResponse
from
pydantic
import
BaseModel
from
dynamo.runtime.logging
import
configure_dynamo_logging
from
dynamo.sdk
import
DYNAMO_IMAGE
,
depends
,
dynamo_endpoint
,
service
from
dynamo.sdk.lib.config
import
ServiceConfig
from
dynamo.sdk.lib.logging
import
configure_server_logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -119,7 +119,7 @@ class Frontend:
def
__init__
(
self
)
->
None
:
# Configure logging
configure_
server
_logging
(
service_name
=
"Frontend"
)
configure_
dynamo
_logging
(
service_name
=
"Frontend"
)
logger
.
info
(
"Starting frontend"
)
config
=
ServiceConfig
.
get_instance
()
...
...
examples/llm/components/planner.py
View file @
974201c8
...
...
@@ -32,9 +32,9 @@ from utils.prefill_queue import PrefillQueue
from
dynamo.llm
import
KvMetricsAggregator
from
dynamo.planner
import
LocalConnector
from
dynamo.runtime
import
DistributedRuntime
,
dynamo_worker
from
dynamo.
sdk.lib
.logging
import
configure_
server
_logging
from
dynamo.
runtime
.logging
import
configure_
dynamo
_logging
configure_
server
_logging
()
configure_
dynamo
_logging
()
logger
=
logging
.
getLogger
(
__name__
)
# will not decrease decode worker number within 3 adjustment interval after a new decode worker
...
...
lib/bindings/python/src/dynamo/runtime/logging.py
View file @
974201c8
...
...
@@ -13,7 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
json
import
logging
import
os
import
tempfile
from
dynamo._core
import
log_message
...
...
@@ -69,3 +72,86 @@ def construct_formatter_prefix(service_name: str | None, worker_id: int | None)
tmp
+=
f
":
{
worker_id
}
"
return
tmp
.
strip
()
def
configure_dynamo_logging
(
service_name
:
str
|
None
=
None
,
worker_id
:
int
|
None
=
None
):
"""
A single place to configure logging for Dynamo.
"""
# First, remove any existing handlers to avoid duplication
root_logger
=
logging
.
getLogger
()
for
handler
in
root_logger
.
handlers
[:]:
root_logger
.
removeHandler
(
handler
)
# Configure the logger with Dynamo's handler
configure_logger
(
service_name
,
worker_id
)
# map the DYN_LOG variable to a logging level
dyn_var
=
os
.
environ
.
get
(
"DYN_LOG"
,
"info"
)
dyn_level
=
log_level_mapping
(
dyn_var
)
configure_vllm_logging
(
dyn_level
)
# loggers that should be configured to ERROR
error_loggers
=
[
"bentoml"
,
"tag"
]
for
logger_name
in
error_loggers
:
logger
=
logging
.
getLogger
(
logger_name
)
logger
.
handlers
=
[]
logger
.
setLevel
(
logging
.
ERROR
)
logger
.
propagate
=
True
def
log_level_mapping
(
level
:
str
)
->
int
:
"""
The DYN_LOG variable is set using "debug" or "trace" or "info.
This function maps those to the appropriate logging level and defaults to INFO
if the variable is not set or a bad value.
"""
if
level
==
"debug"
:
return
logging
.
DEBUG
elif
level
==
"info"
:
return
logging
.
INFO
elif
level
==
"warn"
or
level
==
"warning"
:
return
logging
.
WARNING
elif
level
==
"error"
:
return
logging
.
ERROR
elif
level
==
"critical"
:
return
logging
.
CRITICAL
elif
level
==
"trace"
:
return
logging
.
INFO
else
:
return
logging
.
INFO
def
configure_vllm_logging
(
dyn_level
:
int
):
"""
vLLM requires a logging config file to be set in the environment.
This function creates a temporary file with the VLLM logging config and sets the
VLLM_LOGGING_CONFIG_PATH environment variable to the path of the file.
"""
os
.
environ
[
"VLLM_CONFIGURE_LOGGING"
]
=
"1"
vllm_level
=
logging
.
getLevelName
(
dyn_level
)
# Create a temporary config file for VLLM
vllm_config
=
{
"formatters"
:
{
"simple"
:
{
"format"
:
"%(message)s"
}},
"handlers"
:
{
"dynamo"
:
{
"class"
:
"dynamo.runtime.logging.LogHandler"
,
"formatter"
:
"simple"
,
"level"
:
vllm_level
,
}
},
"loggers"
:
{
"vllm"
:
{
"handlers"
:
[
"dynamo"
],
"level"
:
vllm_level
,
"propagate"
:
False
}
},
"version"
:
1
,
"disable_existing_loggers"
:
False
,
}
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
suffix
=
".json"
,
delete
=
False
)
as
f
:
json
.
dump
(
vllm_config
,
f
)
os
.
environ
[
"VLLM_LOGGING_CONFIG_PATH"
]
=
f
.
name
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment