Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion awscrt/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -40,6 +39,18 @@ 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`. init_logging() must have been called
before using this function or else an exception will be raised.

Args:
log_level (LogLevel): Display messages of this importance and higher.
"""
assert log_level is not None

_awscrt.set_log_level(log_level)


class EventLoopGroup(NativeResource):
"""A collection of event-loops.

Expand Down
5 changes: 5 additions & 0 deletions source/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
22 changes: 22 additions & 0 deletions source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),

Expand Down