Skip to content

logging_v2 cannot log Pandas DataFrames #409

Closed
@astanway

Description

@astanway

Logging

Environment details

  • OS type and version: ubuntu 18.04
  • Python version: 3.6.9
  • pip version: 18.1
  • Pandas version: 0.23.4
  • google-cloud-logging version: 2.6.0

Steps to reproduce

>>> import sys
>>> import logging
>>> from google.cloud.logging_v2.handlers import CloudLoggingHandler
>>> from google.cloud import logging_v2 as glog
>>> log = logging.getLogger()
>>> client = glog.Client()
>>> cloudHandler = CloudLoggingHandler(client, name='logger')
>>> handlers = [cloudHandler]
>>> logging.basicConfig(level=logging.INFO, handlers=handlers)
>>> import pandas as pd
>>> x = pd.DataFrame()
>>> log.info(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1308, in info
    self._log(INFO, msg, args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1444, in _log
    self.handle(record)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1454, in handle
    self.callHandlers(record)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1516, in callHandlers
    hdlr.handle(record)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 861, in handle
    rv = self.filter(record)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 720, in filter
    result = f.filter(record)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/logging_v2/handlers/handlers.py", line 107, in filter
    record._msg_str = str(record.msg).replace('"', '\\"') if record.msg else ""
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 1576, in __nonzero__
    .format(self.__class__.__name__))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions