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
asked a year ago393 views
2 Answers
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
EXPERT
answered a year ago
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
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions