No project description provided
Project description
Custom Logger CloudCity
To unify the way we log and alert to Google Cloud Logger and Sentry, we have created this package.
Changelog
1.0.2 Removed the explicit requirement of havint the CLOUD_LOGGER_NAME environment var set. When none is set, fall back on the default logger
Example
How to use:
- Include the package in your project by doing
pip install custom-logger-cloudcity
- Simply import the module!
Below is an examlpe how to use
import os
os.environ.update({"GOOGLE_APPLICATION_CREDENTIALS": "{Location to you Service account key}"})
os.environ.update({"CLOUD_LOGGER_NAME": "nice_test_logger"}) # Give a name the app will log to
os.environ.update({"ENV": "development"})
# We need to set the environment vars before importing the custom_logger
# You can do so as this example or just set it in the machine wide environment
from custom_logger import custom_logger
if __name__ == '__main__':
# A message as a string will end up in as a textPayload in Google Cloud Logging
custom_logger.info("Hello My Friend")
# Below will not be logged to Google Cloud Logging
custom_logger.error("not ok")
# A message as an argument will end up in as a jsonPayload in Google Cloud Logging
custom_logger.info(some_message="This is a test log in a jsonPayload")
# # An example with multiple arguments
custom_logger.info(
some_message="This is a test log in a jsonPayload",
more_info="It has more info",
and_even_more="These can all be metrics and stuff",
but="We need to make sure that we catch the logging exceptions and print the whole lot",
)
# With message overwrite
custom_logger.info(
message="Let's overwrite the message node",
some_message="This is a test log in a jsonPayload",
more_info="It has more info",
and_even_more="These can all be metrics and stuff",
but="We need to make sure that we catch the logging exceptions and print the whole lot",
)
# You can even nest data, as this is stored as a struct in Google Cloud Logging
custom_logger.info(message="This is message overwrite", amount_transfered=10, amount_failed=10,
errors=["a", "b", "c"])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for custom-logger-cloudcity-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffdd4279465cce0a573023324a72a070bd02ad5daaf9adadbb8c55195a5e167f |
|
MD5 | d5a8e6b382adbc8f0dfee0a9759b94b2 |
|
BLAKE2b-256 | f85b0c4d4e7c8e500afa94ffed7e137e27efebc301c27057be1de9da2472def9 |
Close
Hashes for custom_logger_cloudcity-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f5a6f5499ffcc541068e92cc430f6f2e42fbdc32e41dcefa176eb6d6d1fa5d |
|
MD5 | 3378c547cc8edd850fcfea9ee31813e3 |
|
BLAKE2b-256 | 26df16f9ac840986329d48fc6f95715f79c3ccf88380df698d3b5a0fc93a4b8c |