Skip to content

Commit

Permalink
chore: add documentation for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Jan 6, 2025
1 parent 1fb1c76 commit 9dfd578
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 0 deletions.
46 changes: 46 additions & 0 deletions gapic/templates/README.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,49 @@ Windows
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install \path\to\library


LOGGING
-------

This library has support to enable logging for debugging and monitoring purposes. Note that logs may contain sensitive information and care should be
taken to restrict access to the logs if they are saved, whether it be on local storage or Google Cloud Logging.

Users must **explicitly opt-in** to enable logging by configuring the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable with a valid logging scope.

A logging scope is a namespace that begins with :code:`google`.

- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.

**NOTE**: If an invalid logging scope is configured, we do not act on the corresponding logger.

To set a handler that applies to all Google-based loggers:

.. code-block:: console

export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google

To enable a handler for a specific GAPIC:

.. code-block:: console

export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.abc.v1

:code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` allows users to enable or disable logs by configuring a log system; it does not let them configure log levels, handlers, formatters, etc.

Loggers so configured will handle log messages at level DEBUG or higher, outputting them to stderr. The default log format for these log messages is structured log format.

Alternatively, users can define and configure a valid logging scope using the standard logging library.

A typical use case is the following, which defines a handler that applies to all Google-based loggers:

.. code-block:: python3

import logging

from google.cloud.translate_v3 import translate

base_logger = logging.getLogger("google")
base_logger.addHandler(logging.StreamHandler())
base_logger.setLevel(logging.DEBUG)
Client = translate.TranslationServiceClient()
47 changes: 47 additions & 0 deletions tests/integration/goldens/asset/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,50 @@ Windows
python3 -m venv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install \path\to\library
LOGGING
-------

This library has support to enable logging for debugging and monitoring purposes. Note that logs may contain sensitive information and care should be
taken to restrict access to the logs if they are saved, whether it be on local storage or Google Cloud Logging.

Users must **explicitly opt-in** to enable logging by configuring the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable with a valid logging scope.

A logging scope is a namespace that begins with :code:`google`.

- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.

**NOTE**: If an invalid logging scope is configured, we do not act on the corresponding logger.

To set a handler that applies to all Google-based loggers:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
To enable a handler for a specific GAPIC:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.abc.v1
:code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` allows users to enable or disable logs by configuring a log system; it does not let them configure log levels, handlers, formatters, etc.

Loggers so configured will handle log messages at level DEBUG or higher, outputting them to stderr. The default log format for these log messages is structured log format.

Alternatively, users can define and configure a valid logging scope using the standard logging library.

A typical use case is the following, which defines a handler that applies to all Google-based loggers:

.. code-block:: python3
import logging
from google.cloud.translate_v3 import translate
base_logger = logging.getLogger("google")
base_logger.addHandler(logging.StreamHandler())
base_logger.setLevel(logging.DEBUG)
Client = translate.TranslationServiceClient()
47 changes: 47 additions & 0 deletions tests/integration/goldens/credentials/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,50 @@ Windows
python3 -m venv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install \path\to\library
LOGGING
-------

This library has support to enable logging for debugging and monitoring purposes. Note that logs may contain sensitive information and care should be
taken to restrict access to the logs if they are saved, whether it be on local storage or Google Cloud Logging.

Users must **explicitly opt-in** to enable logging by configuring the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable with a valid logging scope.

A logging scope is a namespace that begins with :code:`google`.

- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.

**NOTE**: If an invalid logging scope is configured, we do not act on the corresponding logger.

To set a handler that applies to all Google-based loggers:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
To enable a handler for a specific GAPIC:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.abc.v1
:code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` allows users to enable or disable logs by configuring a log system; it does not let them configure log levels, handlers, formatters, etc.

Loggers so configured will handle log messages at level DEBUG or higher, outputting them to stderr. The default log format for these log messages is structured log format.

Alternatively, users can define and configure a valid logging scope using the standard logging library.

A typical use case is the following, which defines a handler that applies to all Google-based loggers:

.. code-block:: python3
import logging
from google.cloud.translate_v3 import translate
base_logger = logging.getLogger("google")
base_logger.addHandler(logging.StreamHandler())
base_logger.setLevel(logging.DEBUG)
Client = translate.TranslationServiceClient()
47 changes: 47 additions & 0 deletions tests/integration/goldens/eventarc/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,50 @@ Windows
python3 -m venv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install \path\to\library
LOGGING
-------

This library has support to enable logging for debugging and monitoring purposes. Note that logs may contain sensitive information and care should be
taken to restrict access to the logs if they are saved, whether it be on local storage or Google Cloud Logging.

Users must **explicitly opt-in** to enable logging by configuring the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable with a valid logging scope.

A logging scope is a namespace that begins with :code:`google`.

- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.

**NOTE**: If an invalid logging scope is configured, we do not act on the corresponding logger.

To set a handler that applies to all Google-based loggers:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
To enable a handler for a specific GAPIC:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.abc.v1
:code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` allows users to enable or disable logs by configuring a log system; it does not let them configure log levels, handlers, formatters, etc.

Loggers so configured will handle log messages at level DEBUG or higher, outputting them to stderr. The default log format for these log messages is structured log format.

Alternatively, users can define and configure a valid logging scope using the standard logging library.

A typical use case is the following, which defines a handler that applies to all Google-based loggers:

.. code-block:: python3
import logging
from google.cloud.translate_v3 import translate
base_logger = logging.getLogger("google")
base_logger.addHandler(logging.StreamHandler())
base_logger.setLevel(logging.DEBUG)
Client = translate.TranslationServiceClient()
47 changes: 47 additions & 0 deletions tests/integration/goldens/redis/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,50 @@ Windows
python3 -m venv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install \path\to\library
LOGGING
-------

This library has support to enable logging for debugging and monitoring purposes. Note that logs may contain sensitive information and care should be
taken to restrict access to the logs if they are saved, whether it be on local storage or Google Cloud Logging.

Users must **explicitly opt-in** to enable logging by configuring the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable with a valid logging scope.

A logging scope is a namespace that begins with :code:`google`.

- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.

**NOTE**: If an invalid logging scope is configured, we do not act on the corresponding logger.

To set a handler that applies to all Google-based loggers:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
To enable a handler for a specific GAPIC:

.. code-block:: console
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.abc.v1
:code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` allows users to enable or disable logs by configuring a log system; it does not let them configure log levels, handlers, formatters, etc.

Loggers so configured will handle log messages at level DEBUG or higher, outputting them to stderr. The default log format for these log messages is structured log format.

Alternatively, users can define and configure a valid logging scope using the standard logging library.

A typical use case is the following, which defines a handler that applies to all Google-based loggers:

.. code-block:: python3
import logging
from google.cloud.translate_v3 import translate
base_logger = logging.getLogger("google")
base_logger.addHandler(logging.StreamHandler())
base_logger.setLevel(logging.DEBUG)
Client = translate.TranslationServiceClient()

0 comments on commit 9dfd578

Please sign in to comment.