write log to cloud logging or fluentd, for app in gcp
Project description
GCP Log
Install and config
pip install gcp-mixed-logging
or
pip install -i https://pypi.org/project gcp-mixed-logging
Cloud Logging
Logs Writer: https://cloud.google.com/logging/docs/setup/python
Fluentd
TODO
Usage
from gcp_mixed_logging import mixedlogging
# using on GCE with local fluent
log = mixedlogging('module', stage='prod')
# using with credential and remote fluent host
log = mixedlogging(
'module', stage='prod',
fluent_host='ip or dns', fluent_port=24224,
project='project-id', credentials=Credentials(),
)
# cloud logging: plain text
log.debug("this is a debug message")
log.info("this is a info message")
log.warn("this is a warn message")
log.error("this is a error message")
# cloud logging: struct message
log.info({
"user": "Mark",
"age": 25
})
# fluent:
# 1. time append to log
# 2. send to fluent with tag: 'module-prod.user-info'
log.persist("user-info", {
"user": "Mark",
"age": 25
})
More
Auth 说明
Refer to google.auth
:
-
If the environment variable
GOOGLE_APPLICATION_CREDENTIALS
is set to the path of a valid service account JSON private key file, then it is loaded and returned. The project ID returned is the project ID defined in the service account file if available (some older files do not contain project ID information). -
If the
Google Cloud SDK
_ is installed and has application default credentials set they are loaded and returned.To enable application default credentials with the Cloud SDK run::
`gcloud auth application-default login`
If the Cloud SDK has an active project, the project ID is returned. The active project can be set using::
`gcloud config set project`
-
If the application is running in the
App Engine standard environment
_ then the credentials and project ID from theApp Identity Service
_ are used. -
If the application is running in
Compute Engine
_ or theApp Engine flexible environment
_ then the credentials and project ID are obtained from theMetadata Service
_. -
If no credentials are found, :class:
~google.auth.exceptions.DefaultCredentialsError
will be raised.
Project details
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
Hashes for gcp_mixed_logging-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a22bc636f73b2234863bd8cf33739ba2fb4063d5c82b13c138af263c9f0afd7a |
|
MD5 | 2b834da807f844c9f599f0f330ac15b8 |
|
BLAKE2b-256 | e8c682c218574319b3777708a2aac08c0e2218e5f38df4e4dda06f86393b285d |