Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Adding Logging to Your App

 

The JSA Python helper library (qpylib ) contains two useful functions that you can use to add logging to your app.

The Log() Function

Import the qpylib helper library into your app's views.py to use the log() function. This function writes messages at your chosen log level to the /store/log/app.log file.

By default, logging is turned on and set to INFO level. Lower level logging messages are ignored. Use the POST /log_level endpoint to change log level.

The log() function uses the following format:

def log(message, level='info'):

For example:

from qpylib import qpylib .. #in precedence order from lowest level to highest qpylib.log('debug message' ,'debug') qpylib.log('info message' ,'info') qpylib.log('warning message' ,'warning') qpylib.log('error message' ,'error') qpylib.log('critical message' ,'critical')

Note

All qpylib functions that you import into your app's views.py file can be called globally. For that reason, it is a good idea to add a namespace to the qpylib functions you import to prevent clashes with other functions.

The Set_log_level() Function

You can use this function to set the current log level. This function is used by the POST /log_level endpoint but can also be called programmatically.

def set_log_level(log_level='info'):

Related Documentation