Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Log Handler Formatter #189

Open
thoward-godaddy opened this issue Jul 21, 2022 · 0 comments
Open

Setting Log Handler Formatter #189

thoward-godaddy opened this issue Jul 21, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request investigating p2 Low priority

Comments

@thoward-godaddy
Copy link
Contributor

I'd like to have logs formatted using ecs_logging and noticed adding a handler to my app does nothing to change the log format in the CloudWatch LogGroup.

This for example has no impact to log format:

LOGGER = logging.getLogger(__package__)
LOGGER.setLevel(level=logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(ecs_logging.StdlibFormatter())
LOGGER.addHandler(handler)

I also tried brute forcing the formatter with no luck:

def set_formatter():
    for logger in logging.root.manager.loggerDict.values():
        if isinstance(logger, logging.PlaceHolder):
            continue

        if logger.hasHandlers():
            for handler in logger.handlers:
                handler.setFormatter(ecs_logging.StdlibFormatter())

@hook.handler(HookInvocationPoint.CREATE_PRE_PROVISION)
def pre_create_handler(
    session: Optional[SessionProxy],
    request: BaseHookHandlerRequest,
    callback_context: MutableMapping[str, Any],
    type_configuration: TypeConfigurationModel,
) -> ProgressEvent:
    set_formatter()
    LOGGER.info(jsonify_hook_context(request=request))
    return ProgressEvent(status=OperationStatus.SUCCESS)

Is there a way to set the format for log output using this library?

@ericzbeard ericzbeard added enhancement New feature or request investigating labels Oct 13, 2022
@ericzbeard ericzbeard self-assigned this Oct 13, 2022
@ericzbeard ericzbeard added the p2 Low priority label Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request investigating p2 Low priority
Projects
None yet
Development

No branches or pull requests

2 participants