You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Al our services runs in GCP. To get the best out of the log traces, we should use a common pattern acrosss all functions and services. This documents describes how to use the shared logging functions.
3
+
4
+
## Python functions
5
+
6
+
### Logging level
7
+
The logging level is by default [INFO](https://github.com/MobilityData/mobility-feed-api/blob/a857ca794b5991aa8b6e7ecedb197914ae1eca04/api/src/shared/common/logging_utils.py#L5).
8
+
The logging level can be changed at runtime by setting the function variable `LOGGING_LEVEL` to the desired value, example DEBUG
9
+
10
+
### Initialize logging
11
+
On the main file initialize the logging client by calling the following function:
12
+
```
13
+
init_logger()
14
+
```
15
+
The [init_logger](https://github.com/MobilityData/mobility-feed-api/blob/a857ca794b5991aa8b6e7ecedb197914ae1eca04/functions-python/helpers/logger.py#L49) will set the right logging level and initialize the GCP cloud client if it's not running in local environment.
logging.info("Total feeds: %s", total_feeds) # This will output the following format for total_feeds equals to 10: [mdb-001] Total feeds: 10
35
+
36
+
```
37
+
38
+
Use log parameters instead of string interpolation. String interpolation always creates a string concatenation even if the log is not send due to the environment log level settings.
0 commit comments