From bd5fe35d28be29f1c4cd63962345f4e778fdb0ea Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Thu, 30 Oct 2025 14:22:11 -0700 Subject: [PATCH 1/5] bind out setting of loglevel --- awscrt/io.py | 11 +++++++++++ source/io.h | 5 +++++ source/module.c | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/awscrt/io.py b/awscrt/io.py index faaa46844..dc5306c02 100644 --- a/awscrt/io.py +++ b/awscrt/io.py @@ -40,6 +40,17 @@ def init_logging(log_level, file_name): _awscrt.init_logging(log_level, file_name) +def set_log_level(log_level): + """Change the log level of `awscrt`. + + Args: + log_level (LogLevel): Display messages of this importance and higher. + `LogLevel.NoLogs` will disable logging. + """ + assert log_level is not None + + _awscrt.set_log_level(log_level) + class EventLoopGroup(NativeResource): """A collection of event-loops. diff --git a/source/io.h b/source/io.h index 4fbb1064d..fed29d856 100644 --- a/source/io.h +++ b/source/io.h @@ -23,6 +23,11 @@ bool aws_py_socket_options_init(struct aws_socket_options *socket_options, PyObj */ PyObject *aws_py_init_logging(PyObject *self, PyObject *args); +/** + * Change logging level of the global logger. + */ +PyObject *aws_py_set_log_level(PyObject *self, PyObject *args); + /** * Returns True if ALPN is available, False if it is not. */ diff --git a/source/module.c b/source/module.c index fff5a96b2..be4afdca1 100644 --- a/source/module.c +++ b/source/module.c @@ -86,6 +86,27 @@ PyObject *aws_py_init_logging(PyObject *self, PyObject *args) { Py_RETURN_NONE; } +PyObject *aws_py_set_log_level(PyObject *self, PyObject *args) { + (void)self; + + if (!s_logger_init) { + aws_raise_error(AWS_ERROR_INVALID_STATE); + return PyErr_AwsLastError(); + } + + int log_level = 0; + if (!PyArg_ParseTuple(args, "b", &log_level)) { + PyErr_SetNone(PyExc_ValueError); + return NULL; + } + + if (aws_logger_set_log_level(&s_logger, log_level) != AWS_OP_SUCCESS) { + return PyErr_AwsLastError(); + } + + Py_RETURN_NONE; +} + struct aws_byte_cursor aws_byte_cursor_from_pyunicode(PyObject *str) { Py_ssize_t len; const char *ptr = PyUnicode_AsUTF8AndSize(str, &len); @@ -761,6 +782,7 @@ static PyMethodDef s_module_methods[] = { AWS_PY_METHOD_DEF(tls_connection_options_set_alpn_list, METH_VARARGS), AWS_PY_METHOD_DEF(tls_connection_options_set_server_name, METH_VARARGS), AWS_PY_METHOD_DEF(init_logging, METH_VARARGS), + AWS_PY_METHOD_DEF(set_log_level, METH_VARARGS), AWS_PY_METHOD_DEF(input_stream_new, METH_VARARGS), AWS_PY_METHOD_DEF(pkcs11_lib_new, METH_VARARGS), From 30198b5ee46e609fdbb9337a655c7905227b9edd Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Thu, 30 Oct 2025 14:25:26 -0700 Subject: [PATCH 2/5] lint --- awscrt/io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/awscrt/io.py b/awscrt/io.py index dc5306c02..e65e18c30 100644 --- a/awscrt/io.py +++ b/awscrt/io.py @@ -51,6 +51,7 @@ def set_log_level(log_level): _awscrt.set_log_level(log_level) + class EventLoopGroup(NativeResource): """A collection of event-loops. From 55a45da16df19da6bf8f31d5dff2b2a8d038cec7 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Thu, 30 Oct 2025 14:43:27 -0700 Subject: [PATCH 3/5] add pre-requisite explainer --- awscrt/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/awscrt/io.py b/awscrt/io.py index e65e18c30..8f648f98e 100644 --- a/awscrt/io.py +++ b/awscrt/io.py @@ -41,7 +41,8 @@ def init_logging(log_level, file_name): def set_log_level(log_level): - """Change the log level of `awscrt`. + """Change the log level of `awscrt`. init_logging() must have been called + before using this function. Args: log_level (LogLevel): Display messages of this importance and higher. From be0b536639eeb7f5e40432237be94402cd3fdb47 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Thu, 30 Oct 2025 14:44:39 -0700 Subject: [PATCH 4/5] remove NoLogs description from init_logging --- awscrt/io.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/awscrt/io.py b/awscrt/io.py index 8f648f98e..2bfcfbed1 100644 --- a/awscrt/io.py +++ b/awscrt/io.py @@ -30,7 +30,6 @@ def init_logging(log_level, file_name): Args: log_level (LogLevel): Display messages of this importance and higher. - `LogLevel.NoLogs` will disable logging. file_name (str): Logging destination. To write to stdout or stderr pass 'stdout' or 'stderr' as strings. Otherwise, a file path is assumed. """ @@ -46,7 +45,6 @@ def set_log_level(log_level): Args: log_level (LogLevel): Display messages of this importance and higher. - `LogLevel.NoLogs` will disable logging. """ assert log_level is not None From f4920da23c82afcb05f3ed2ba04dcb033b3c800f Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 31 Oct 2025 08:09:44 -0700 Subject: [PATCH 5/5] pr changes --- awscrt/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awscrt/io.py b/awscrt/io.py index 2bfcfbed1..4d36ba69f 100644 --- a/awscrt/io.py +++ b/awscrt/io.py @@ -41,7 +41,7 @@ def init_logging(log_level, file_name): def set_log_level(log_level): """Change the log level of `awscrt`. init_logging() must have been called - before using this function. + before using this function or else an exception will be raised. Args: log_level (LogLevel): Display messages of this importance and higher.