Thundra APM
Search…
Deployment Integrations
Configuring Logs for Python SDK

Configuring Python Log Support

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.

Configuring Log Support via Config File

This process involves adding logging environment variables to your config.ini file, as shown below:
Configuring using log file
1
[loggers]
2
keys=root
3
4
[handlers]
5
keys=thundraHandler
6
7
[formatters]
8
keys=simpleFormatter
9
10
[logger_root]
11
level=NOTSET
12
handlers=thundraHandler
13
14
[handler_thundraHandler]
15
class=ThundraLogHandler
16
level=NOTSET
17
formatter=simpleFormatter
18
args=()
19
20
[formatter_simpleFormatter]
21
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
22
datefmt=
Copied!
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 File
1
from thundra.thundra_agent import Thundra
2
thundra = Thundra()
3
import logging
4
import logging.config
5
from thundra.plugins.log.thundra_log_handler import ThundraLogHandler
6
7
logging.config.fileConfig('config.ini')
8
9
@thundra
10
def handler(event, context):
11
...
Copied!

Adding Logger Programmatically

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:
1
from thundra.thundra_agent import Thundra
2
import logging
3
from thundra.plugins.log.thundra_log_handler import ThundraLogHandler
4
5
thundra = Thundra()
6
7
logger = logging.getLogger('handler')
8
logger.setLevel(logging.DEBUG)
9
handler = ThundraLogHandler()
10
logger.addHandler(handler)
11
12
13
@thundra
14
def handler(event, context):
15
16
logger.error('This is an error log')
17
response = {
18
'message': 'Hello Thundra!'
19
}
20
return response
Copied!

Enabling Log Plugin

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.

Enabling log programmatically on agent initialization

Programmatic Log Plugin Configuration
1
thundra = Thundra(api_key=’my_api_key’, disable_log=False)
Copied!

Enabling log using environment variables

Log Plugin Configuration via Environment Variables
1
thundra_apiKey: ${self:custom.thundraApiKey}
2
thundra_agent_lambda_log_disable: false
Copied!