Skip to main content

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:

  1. 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).

  2. 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`
    
  3. If the application is running in the App Engine standard environment_ then the credentials and project ID from the App Identity Service_ are used.

  4. If the application is running in Compute Engine_ or the App Engine flexible environment_ then the credentials and project ID are obtained from the Metadata Service_.

  5. 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

gcp-mixed-logging-0.0.3.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcp_mixed_logging-0.0.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file gcp-mixed-logging-0.0.3.tar.gz.

File metadata

  • Download URL: gcp-mixed-logging-0.0.3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for gcp-mixed-logging-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2f6e8d0f6d36d2bf7052fb75aa4d7cbd3389a3af62515770fea4768b96b160e0
MD5 3bbef00387f8fe50bb7804efb0d871be
BLAKE2b-256 bd41dde3d5c2543653dde1e84fedb65e0c884379a5d5226b4e7e0a9904fe7079

See more details on using hashes here.

File details

Details for the file gcp_mixed_logging-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: gcp_mixed_logging-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for gcp_mixed_logging-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3c18875171e6d3be29ad59d3937588c0f8687b2a3e035d31a57d19e54ffb6d14
MD5 727582323e8340a16300e17edead66f7
BLAKE2b-256 cd3af25d90c05f67bd3a1163e13adbaf8e24d143a40ba3537fab7b9a552ed556

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page