Greengrass LOG_LEVEL with custom components using Log4j

0

Hi,

we use log4j to manage logging in our custom components for greengrass (v2). i.e.

log.error("Something terrible happened") or log.info("Just something I like to log")

However, I find that regardless of the level, it is always logged as "INFO" level in the greengrass compoment logs in cloudwatch. i.e.

{"thread":"Copier","level":"INFO","eventType":"stdout","message":"ERROR [<cut>:64] Something terrible happened {error_message=<cut>}

Is there a way to map this properly? Now we have to sync all log levels to cloudwatch to do i.e. monitoring or cloudwatch alarms.

Thanks J

johans
已提問 1 年前檢視次數 408 次
2 個答案
0

Hi,

the "INFO" level you see in the logs generated by Greengrass cannot be changed. Greengrass captures all the output going to stdout and stderr and copies it to its own logs. stdout lines are logged at "INFO" level, stderr lines are logged at "ERROR" level. The loglevel from your own logger will be part of the message. You can redirect your logs to a separate file to have a cleaner log output. You can also extract your original log lines from the message field in the Greengrass logs.

AWS
專家
已回答 1 年前
0

Hey @johans,

@MassimilianoAWS is right. If you want to have your logs written in your desired level and have them uploaded to cloudwatch. Change your log configuration to write logs into files in your files system and specify a rotation policy. Then, you can use the Log Manager component to target your log files and have your component logs in the log level you desire.

Please note that if you want to use the Log Manager component to filter out your logs by log level, your logs need to be written in a specific JSON format.

AWS
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南