Skip to main content

custom_logging.py

Source: sunholo/custom_logging.py

Functions

get_logger()

No docstring available.

is_logging_setup(logger=None)

No docstring available.

log_folder_location(folder_name)

No docstring available.

setup_logging(logger_name=None, log_level=20, project_id=None)

Sets up Google Cloud Logging with the provided log level and project ID. If no project ID is provided, it attempts to retrieve the project ID from the metadata server.

Parameters: logger_name (str): The name of the log to send to. If not provided, set to run.googleapis.com%2Fstderr log_level: The logging level to capture. Uses Python's logging module levels. Default is log.INFO. project_id: A string representing the Google Cloud project ID. If None, the project ID will be retrieved from the metadata server.

Example:

Set up Google Cloud Logging for the script with default INFO level

setup_logging()

Now you can use Python's logging module as usual

import logging log.info('This is an info message that will be sent to Google Cloud log.')

Note: This function requires that the 'google-cloud-logging' library is installed and that the application is authenticated with Google Cloud. This can be done by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your service account key file, or by running this code in an environment where default application credentials are already set, such as Google Cloud Compute Engine, Google Kubernetes Engine, Google App Engine, etc.

Classes

GoogleCloudLogging

No docstring available.

  • init(self, project_id=None, log_level=20, logger_name=None)

    • Initialize self. See help(type(self)) for accurate signature.
  • new(cls, project_id=None, log_level=20, logger_name=None)

    • Create and return a new object. See help(type) for accurate signature.
  • _get_caller_info(self)

    • Internal method to get caller's filename, line number, and function name.
  • debug(self, log_text=None, log_struct=None)

    • Writes a debug log entry.

Args: log_text (str, optional): The debug log message as a text string. Defaults to None. log_struct (dict, optional): The debug log message as structured data. Defaults to None. logger_name (str, optional): The name of the logger to which to write the debug log entry.

  • error(self, log_text=None, log_struct=None)
    • Writes an error log entry.

Args: log_text (str, optional): The error log message as a text string. Defaults to None. log_struct (dict, optional): The error log message as structured data. Defaults to None. logger_name (str, optional): The name of the logger to which to write the error log entry.

  • exception(self, log_text=None, log_struct=None)
    • Writes an exception log entry.

Args: log_text (str, optional): The error log message as a text string. Defaults to None. log_struct (dict, optional): The error log message as structured data. Defaults to None. logger_name (str, optional): The name of the logger to which to write the error log entry.

  • info(self, log_text=None, log_struct=None)
    • Writes an info log entry.

Args: log_text (str, optional): The info log message as a text string. Defaults to None. log_struct (dict, optional): The info log message as structured data. Defaults to None. logger_name (str, optional): The name of the logger to which to write the info log entry.

  • setup_logging(self, log_level=20, logger_name=None)

    • No docstring available.
  • structured_log(self, log_text=None, log_struct=None, logger_name=None, severity='INFO')

    • Writes log entries to the specified logger as either text or structured data.

Args: log_text (str, optional): The log message as a text string. Defaults to None. log_struct (dict, optional): The log message as a dictionary for structured log. Defaults to None. logger_name (str, optional): The name of the logger to which to write the log entries. e.g. logName="run.googleapis.com%2Fstderr" severity (str, optional): The severity level of the log entry. Defaults to "INFO".

  • warning(self, log_text=None, log_struct=None)
    • Writes a warning log entry.

Args: log_text (str, optional): The warning log message as a text string. Defaults to None. log_struct (dict, optional): The warning log message as structured data. Defaults to None. logger_name (str, optional): The name of the logger to which to write the warning log entry.

Sunholo Multivac

Get in touch to see if we can help with your GenAI project.

Contact us

Other Links

Sunholo Multivac - GenAIOps

Copyright ©

Holosun ApS 2024