Skip to content

Commit 3755e68

Browse files
peterstone2017wangbill1993
andauthored
Enable debug logging add recommendation (#948)
* enable debug logging recommendation log * Fix logging.py change style * style fix * remove test * use aka.ms link Co-authored-by: wangbill <[email protected]>
1 parent 3d49d5b commit 3755e68

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
from . import functions
2525
from . import loader
2626
from . import protos
27+
from .bindings.shared_memory_data_transfer import SharedMemoryManager
2728
from .constants import (PYTHON_THREADPOOL_THREAD_COUNT,
2829
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
2930
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
3031
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
3132
PYTHON_ENABLE_DEBUG_LOGGING)
33+
from .extension import ExtensionManager
3234
from .logging import disable_console_logging, enable_console_logging
35+
from .logging import enable_debug_logging_recommendation
3336
from .logging import (logger, error_logger, is_system_log_category,
3437
CONSOLE_LOG_PREFIX)
35-
from .extension import ExtensionManager
3638
from .utils.common import get_app_setting, is_envvar_true
37-
from .utils.tracing import marshall_exception_trace
3839
from .utils.dependency import DependencyManager
40+
from .utils.tracing import marshall_exception_trace
3941
from .utils.wrappers import disable_feature_by
40-
from .bindings.shared_memory_data_transfer import SharedMemoryManager
4142

4243
_TRUE = "true"
4344

@@ -262,6 +263,7 @@ async def _handle__worker_init_request(self, req):
262263
logger.info('Received WorkerInitRequest, '
263264
'python version %s, worker version %s, request ID %s',
264265
sys.version, __version__, self.request_id)
266+
enable_debug_logging_recommendation()
265267

266268
worker_init_request = req.worker_init_request
267269
host_capabilities = worker_init_request.capabilities
@@ -459,6 +461,7 @@ async def _handle__function_environment_reload_request(self, req):
459461
try:
460462
logger.info('Received FunctionEnvironmentReloadRequest, '
461463
'request ID: %s', self.request_id)
464+
enable_debug_logging_recommendation()
462465

463466
func_env_reload_request = req.function_environment_reload_request
464467

azure_functions_worker/logging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def enable_console_logging() -> None:
7676
logger.addHandler(handler)
7777

7878

79+
def enable_debug_logging_recommendation():
80+
logging.info("To enable debug level logging, please refer to "
81+
"https://aka.ms/python-enable-debug-logging")
82+
83+
7984
def is_system_log_category(ctg: str) -> bool:
8085
"""Check if the logging namespace belongs to system logs. Category starts
8186
with the following name will be treated as system logs.

tests/unittests/test_dispatcher.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,36 @@ async def test_dispatcher_initialize_worker_logging(self):
6969
1
7070
)
7171

72+
self.assertEqual(
73+
len([l for l in r.logs if l.message.startswith(
74+
'To enable debug level logging'
75+
)]),
76+
1
77+
)
78+
79+
async def test_dispatcher_environment_reload_logging(self):
80+
"""Test if the sync threadpool will pick up app setting in placeholder
81+
mode (Linux Consumption)
82+
"""
83+
async with self._ctrl as host:
84+
await self._check_if_function_is_ok(host)
85+
86+
# Reload environment variable on specialization
87+
r = await host.reload_environment(environment={})
88+
self.assertEqual(
89+
len([l for l in r.logs if l.message.startswith(
90+
'Received FunctionEnvironmentReloadRequest'
91+
)]),
92+
1
93+
)
94+
95+
self.assertEqual(
96+
len([l for l in r.logs if l.message.startswith(
97+
'To enable debug level logging'
98+
)]),
99+
1
100+
)
101+
72102
async def test_dispatcher_send_worker_request(self):
73103
"""Test if the worker status response will be sent correctly when
74104
a worker status request is received

0 commit comments

Comments
 (0)