aws-cloudformation / aws-cloudformation/cloudformation-cli-python-plugin

Setting Log Handler Formatter

未關閉
#189 0 則留言 1 個 reaction 已指派 1 人 已被 @ericzbeard 認領 在 GitHub 檢視
enhancement investigating p2
主要語言
Python
星號
107
分支
46
PR 合併指標
30 天內沒有已合併 PR

描述

I'd like to have logs formatted using [ecs_logging](https://www.elastic.co/guide/en/ecs-logging/python/current/installation.html#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?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。