Search code examples
python-3.xgoogle-cloud-functionsgoogle-cloud-stackdriverpython-logging

The google-cloud-logging module is not logging to the correct severity filters in StackDriver


I am having an issue where the google cloud logging module does not appear to log to the correct severity filter in StackDriver. I've tried both V1 and V2 of the module, but I can only ever get things to log to the info severity or error severity. We could really use the log levels to match up to the severity filters so that statements like logging.debug actually print to the StackDriver Debug severity. In addition, we want it so that these messages can be sent as a dict object if we need to provide more info, and posted to the function logs, instead of global logs in StackDriver.

The only way I could get this working was this clunky log method log_struct, and I had to pass in a resource into each log, making it cumbersome for the other developers. I could really use a better way to log to StackDriver with as little work for the others as possible.


Solution

  • I ran into this issue on my project and after much trouble finally got a setup that could log to StackDriver based on severity. I discovered that I would need to replicate this in each environment and google cloud function my project had, so i built it out into a python module and put it on pypi for others to use. https://pypi.org/project/gcp-python-logging/

    This replicates much of the logging style of Python logging, but translates it nicely into StackDriver severity levels. One of the first modules in Python i've made, and will be continuing to clean it up, but let me know if there are other features and functionality desired.