Skip to content

Support crt logs in 'logging' module#728

Open
azkrishpy wants to merge 22 commits intomainfrom
py-logging
Open

Support crt logs in 'logging' module#728
azkrishpy wants to merge 22 commits intomainfrom
py-logging

Conversation

@azkrishpy
Copy link
Copy Markdown
Contributor

@azkrishpy azkrishpy commented Apr 2, 2026

Issue #, if available:

Description of changes:
CRT log messages can now be routed through Python's standard logging module via the awscrt.logging module.

Usage:

import logging
from awscrt.logging import init_logging, CRT_LOG_FORMAT

handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(CRT_LOG_FORMAT))
logging.getLogger('awscrt').addHandler(handler)
init_logging(logging.DEBUG)

Note: Existing awscrt.io.init_logging() is retained for backward compatibility, however CRT cannot publish to multiple subscribers, so only one of the loggers can be initialized.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@azkrishpy azkrishpy marked this pull request as ready for review April 7, 2026 00:43
source/module.c Outdated
Comment on lines +148 to +152
/* Fill header */
struct s_py_log_header *header = (struct s_py_log_header *)output->bytes;
header->level = level;
header->thread_name_len = thread_name.len;
header->subject_len = subject_name.len;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this is hacky, I spent 5 mins to understand this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants