2 Answers
- Newest
- Most votes
- Most comments
1
Hi Simon,
As you have determined, writing to stdout is logged at info and stderr is at warn. There is no way to use any different log levels in the Greengrass logger. You can certainly though using Python's builtin logging library to log to a file of your choosing which gives you full control over the log level and format.
0
Hello, thank you for the quick reply.
Just to clarify - if we use the Python's logging module to log to the standard output, we can surely specify different logging levels:
import logging
logger = logging.getLogger()
handler = logging.StreamHandler(sys.stdout)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
logger.debug('This is a debug')
logger.info('This is an info')
logger.warning('This is a warning')
logger.error('This is an error')
The above code produces the following output. As we can notice, the field 'level' is set to 'INFO' in all of the entries (given that the stream handler is set to standard output). Is this indeed the expected behaviour?
{"thread":"Copier","level":"INFO","eventType":"stdout","message":"This is a debug","contexts":{"scriptName":"services.TEST.lifecycle.Run.Script","serviceName":"TEST","currentState":"RUNNING"},"loggerName":"TEST","timestamp":1646063970436,"cause":null}
{"thread":"Copier","level":"INFO","eventType":"stdout","message":"This is an info","contexts":{"scriptName":"services.TEST.lifecycle.Run.Script","serviceName":"TEST","currentState":"RUNNING"},"loggerName":"TEST","timestamp":1646063970436,"cause":null}
{"thread":"Copier","level":"INFO","eventType":"stdout","message":"This is a warning","contexts":{"scriptName":"services.TEST.lifecycle.Run.Script","serviceName":"TEST","currentState":"RUNNING"},"loggerName":"TEST","timestamp":1646063970436,"cause":null}
{"thread":"Copier","level":"INFO","eventType":"stdout","message":"This is an error","contexts":{"scriptName":"services.TEST.lifecycle.Run.Script","serviceName":"TEST","currentState":"RUNNING"},"loggerName":"TEST","timestamp":1646063970436,"cause":null}
answered 2 years ago
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 2 years ago