In order to use Thundra's log support, you need to add ThundraLogHandler
to your logger. You can add this handler by logging the configuration file or you can directly add this handler to your logger object.
This process involves adding logging environment variables to your config.ini file, as shown below:
Configuring using log file[loggers]keys=root[handlers]keys=thundraHandler[formatters]keys=simpleFormatter[logger_root]level=NOTSEThandlers=thundraHandler[handler_thundraHandler]class=ThundraLogHandlerlevel=NOTSETformatter=simpleFormatterargs=()[formatter_simpleFormatter]format=%(asctime)s - %(name)s - %(levelname)s - %(message)sdatefmt=
As can be seen from the configurations specified in the code snippet above, the Log Support parameters (such as level and handlers to monitor) are set. Moreover, you can also specify a format for how you would prefer to view your log message, specified as
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s.
You can then import the config file by using the Python logging configurations, as shown in the code snippet below:
Importing Config Filefrom thundra.thundra_agent import Thundrathundra = Thundra()import loggingimport logging.configfrom thundra.plugins.log.thundra_log_handler import ThundraLogHandlerlogging.config.fileConfig('config.ini')@thundradef handler(event, context):...
To configure and add Log Support within your Python modules, you will first have to import the logging library and get a logging. You will then need to add the handler to the logging instance, as shown in the code snippet below:
from thundra.thundra_agent import Thundraimport loggingfrom thundra.plugins.log.thundra_log_handler import ThundraLogHandlerthundra = Thundra()logger = logging.getLogger('handler')logger.setLevel(logging.DEBUG)handler = ThundraLogHandler()logger.addHandler(handler)@thundradef handler(event, context):logger.error('This is an error log')response = {'message': 'Hello Thundra!'}return response
By default, log monitoring is disabled, but it can be enabled by setting the relevant configuration parameters. These parameters include the thundra_agent_lambda_log_disable
environment variable and the disable_log
object initialization parameter.
Programmatic Log Plugin Configurationthundra = Thundra(api_key=’my_api_key’, disable_log=False)
Log Plugin Configuration via Environment Variablesthundra_apiKey: ${self:custom.thundraApiKey}thundra_agent_lambda_log_disable: false