当前位置: 首页>>代码示例>>Python>>正文


Python logging.Client方法代码示例

本文整理汇总了Python中google.cloud.logging.Client方法的典型用法代码示例。如果您正苦于以下问题:Python logging.Client方法的具体用法?Python logging.Client怎么用?Python logging.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.cloud.logging的用法示例。


在下文中一共展示了logging.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: configure

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def configure(project=LOGGING_PROJECT):
    """Configures cloud logging

    This is called for all main calls. If a $LOGGING_PROJECT is environment
    variable configured, then STDERR and STDOUT are redirected to cloud
    logging.
    """
    if not project:
        sys.stderr.write('!! Error: The $LOGGING_PROJECT enviroment '
                         'variable is required in order to set up cloud logging. '
                         'Cloud logging is disabled.\n')
        return

    logging.basicConfig(level=logging.INFO)
    try:
        # if this fails, redirect stderr to /dev/null so no startup spam.
        with contextlib.redirect_stderr(io.StringIO()):
            client = glog.Client(project)
            client.setup_logging(logging.INFO)
    except:
        sys.stderr.write('!! Cloud logging disabled\n') 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:23,代码来源:cloud_logging.py

示例2: setup_stackdriver_handler

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def setup_stackdriver_handler(project_id):
  """Set up Google Cloud Stackdriver Logging

  The Google Cloud Logging library will attach itself as a
  handler to the default Python logging module.

  Attributes:
    project_id: The name of the Google Cloud project.
  Raises:
    TurbiniaException: When an error occurs enabling GCP Stackdriver Logging.
  """
  try:
    client = cloud_logging.Client(project=project_id)
    cloud_handler = cloud_logging.handlers.CloudLoggingHandler(client)
    logger = logging.getLogger('turbinia')
    logger.addHandler(cloud_handler)
  except exceptions.GoogleCloudError as exception:
    msg = 'Error enabling Stackdriver Logging: {0:s}'.format(str(exception))
    raise TurbiniaException(msg) 
开发者ID:google,项目名称:turbinia,代码行数:21,代码来源:google_cloud.py

示例3: setup_stackdriver_traceback

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def setup_stackdriver_traceback(project_id):
  """Set up Google Cloud Error Reporting

  This method will enable Google Cloud Error Reporting.
  All exceptions that occur within a Turbinia Task will be logged.

  Attributes:
    project_id: The name of the Google Cloud project.
  Raises:
    TurbiniaException: When an error occurs enabling GCP Error Reporting.
  """
  try:
    client = error_reporting.Client(project=project_id)
  except exceptions.GoogleCloudError as exception:
    msg = 'Error enabling GCP Error Reporting: {0:s}'.format(str(exception))
    raise TurbiniaException(msg)
  return client 
开发者ID:google,项目名称:turbinia,代码行数:19,代码来源:google_cloud.py

示例4: run_quickstart

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def run_quickstart():
    # [START logging_quickstart]
    # Imports the Google Cloud client library
    from google.cloud import logging

    # Instantiates a client
    logging_client = logging.Client()

    # The name of the log to write to
    log_name = 'my-log'
    # Selects the log to write to
    logger = logging_client.logger(log_name)

    # The data to log
    text = 'Hello, world!'

    # Writes the log entry
    logger.log_text(text)

    print('Logged: {}'.format(text))
    # [END logging_quickstart] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:quickstart.py

示例5: write_entry

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def write_entry(logger_name):
    """Writes log entries to the given logger."""
    logging_client = logging.Client()

    # This log can be found in the Cloud Logging console under 'Custom Logs'.
    logger = logging_client.logger(logger_name)

    # Make a simple text log
    logger.log_text('Hello, world!')

    # Simple text log with severity.
    logger.log_text('Goodbye, world!', severity='ERROR')

    # Struct log. The struct can be any JSON-serializable dictionary.
    logger.log_struct({
        'name': 'King Arthur',
        'quest': 'Find the Holy Grail',
        'favorite_color': 'Blue'
    })

    print('Wrote logs to {}.'.format(logger.name))
# [END logging_write_log_entry]


# [START logging_list_log_entries] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:27,代码来源:snippets.py

示例6: test_create

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def test_create(capsys):
    sink_name = TEST_SINK_NAME_TMPL.format(_random_id())

    try:
        export.create_sink(
            sink_name,
            BUCKET,
            TEST_SINK_FILTER)
    # Clean-up the temporary sink.
    finally:
        try:
            logging.Client().sink(sink_name).delete()
        except Exception:
            pass

    out, _ = capsys.readouterr()
    assert sink_name in out 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:19,代码来源:export_test.py

示例7: update_sink

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def update_sink(sink_name, filter_):
    """Changes a sink's filter.

    The filter determines which logs this sink matches and will be exported
    to the destination. For example a filter of 'severity>=INFO' will send
    all logs that have a severity of INFO or greater to the destination.
    See https://cloud.google.com/logging/docs/view/advanced_filters for more
    filter information.
    """
    logging_client = logging.Client()
    sink = logging_client.sink(sink_name)

    sink.reload()

    sink.filter_ = filter_
    print('Updated sink {}'.format(sink.name))
    sink.update()
# [END logging_update_sink]


# [START logging_delete_sink] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:export.py

示例8: __init__

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def __init__(self, name, to_cloud=True):
        self.to_cloud = to_cloud

        if self.to_cloud:
            # Initialize the Stackdriver logging and error reporting clients.
            self.cloud_logger = logging.Client().logger(name)
            self.error_client = error_reporting.Client()

            # Initialize the local fallback logger.
            self.fallback_logger, fallback_handler = self.get_local_logger(
                name, FALLBACK_LOG_FILE)

            # Redirect the backoff logs to the local fallback handler.
            backoff_logger = getLogger("backoff")
            backoff_logger.setLevel(DEBUG)
            backoff_logger.handlers = [fallback_handler]
        else:
            # Initialize the local file logger.
            self.local_logger, _ = self.get_local_logger(name, LOG_FILE) 
开发者ID:maxbbraun,项目名称:trump2cash,代码行数:21,代码来源:logs.py

示例9: configure

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def configure(project=LOGGING_PROJECT):
    """Configures cloud logging

    This is called for all main calls. If a $LOGGING_PROJECT is environment
    variable configured, then STDERR and STDOUT are redirected to cloud
    logging.
    """
    if not project:
        sys.stderr.write('!! Error: The $LOGGING_PROJECT enviroment '
                         'variable is required in order to set up cloud logging. '
                         'Cloud logging is disabled.\n')
        return

    try:
        # if this fails, redirect stderr to /dev/null so no startup spam.
        with contextlib.redirect_stderr(io.StringIO()):
            client = glog.Client(project)
            client.setup_logging(logging.INFO)
    except:
        logging.basicConfig(level=logging.INFO)
        sys.stderr.write('!! Cloud logging disabled\n') 
开发者ID:mlperf,项目名称:training,代码行数:23,代码来源:cloud_logging.py

示例10: get_sinks

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def get_sinks(self, project_id: str):
        try:
            client = stackdriverlogging.Client(project=project_id)
            return await run_concurrently(lambda: [sink for sink in client.list_sinks()])
        except Exception as e:
            print_exception('Failed to retrieve sinks: {}'.format(e))
            return [] 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:9,代码来源:stackdriverlogging.py

示例11: get_metrics

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def get_metrics(self, project_id: str):
        try:
            client = stackdriverlogging.Client(project=project_id)
            return await run_concurrently(lambda: [metric for metric in client.list_metrics()])
        except Exception as e:
            print_exception('Failed to retrieve metrics: {}'.format(e))
            return [] 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:9,代码来源:stackdriverlogging.py

示例12: _client

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def _client(self) -> gcp_logging.Client:
        """Google Cloud Library API client"""
        credentials = get_credentials_and_project_id(
            key_path=self.gcp_key_path,
            scopes=self.scopes,
        )
        client = gcp_logging.Client(
            credentials=credentials,
            client_info=ClientInfo(client_library_version='airflow_v' + version.version)
        )
        return client 
开发者ID:apache,项目名称:airflow,代码行数:13,代码来源:stackdriver_task_handler.py

示例13: list_entries

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def list_entries(logger_name):
    """Lists the most recent entries for a given logger."""
    logging_client = logging.Client()
    logger = logging_client.logger(logger_name)

    print('Listing entries for logger {}:'.format(logger.name))

    for entry in logger.list_entries():
        timestamp = entry.timestamp.isoformat()
        print('* {}: {}'.format
              (timestamp, entry.payload))
# [END logging_list_log_entries]


# [START logging_delete_log] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:17,代码来源:snippets.py

示例14: delete_logger

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def delete_logger(logger_name):
    """Deletes a logger and all its entries.

    Note that a deletion can take several minutes to take effect.
    """
    logging_client = logging.Client()
    logger = logging_client.logger(logger_name)

    logger.delete()

    print('Deleted all logging entries for {}'.format(logger.name))
# [END logging_delete_log] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:14,代码来源:snippets.py

示例15: example_log

# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import Client [as 别名]
def example_log():
    client = logging.Client()
    logger = client.logger(TEST_LOGGER_NAME)
    text = 'Hello, world.'
    logger.log_text(text)
    return text 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:8,代码来源:snippets_test.py


注:本文中的google.cloud.logging.Client方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。