gigl.common.logger#

Classes#

Logger

GiGL's custom logger class used for local and cloud logging (VertexAI, Dataflow, etc.)

Module Contents#

class gigl.common.logger.Logger(logger=None, name=None, log_to_file=False, extra=None)[source]#

Bases: logging.LoggerAdapter

GiGL’s custom logger class used for local and cloud logging (VertexAI, Dataflow, etc.)

On App Engine and Kubernetes, records are routed to Google Cloud Logging, which renders them as GCP JSON. Set GIGL_DISABLE_CLOUD_LOGGING to fall back to the console format.

Parameters:
  • logger (Optional[logging.Logger]) – A custom logger to use. If not provided, the default logger will be created.

  • name (Optional[str]) – The name to be used for the logger. By default uses “root”.

  • log_to_file (bool) – If True, logs will be written to a file. If False, logs will be written to the console.

  • extra (Optional[dict[str, Any]]) – Extra information to be added to the log message.

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))

process(msg, kwargs)[source]#

Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.

Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.

Parameters:
  • msg (str)

  • kwargs (MutableMapping[str, Any])

Return type:

Any