Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging: Crash if using non default log level names with CloudLoggingHandler #7213

Closed
josteinl opened this issue Jan 28, 2019 · 1 comment · Fixed by #8837
Closed

Logging: Crash if using non default log level names with CloudLoggingHandler #7213

josteinl opened this issue Jan 28, 2019 · 1 comment · Fixed by #8837
Assignees
Labels
api: logging Issues related to the Cloud Logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@josteinl
Copy link

Environment details

  1. OS: Ubuntu 18.04.1 LTS (ubuntu-bionic)
  2. Python version: 3.6.7
  3. google-cloud-logging version: 1.10.0

Steps to reproduce

Use GCP logging with non default log level name. Crashes every time. See code below using the non default log level name 'ERR'.

Code example

import logging

from google.cloud import logging as cloud_logging
from google.cloud.logging.handlers import CloudLoggingHandler

client = cloud_logging.Client()

handler = CloudLoggingHandler(client)
cloud_logger = logging.getLogger("cloudLogger")
cloud_logger.setLevel(logging.INFO)
cloud_logger.addHandler(handler)

cloud_logger.error("First bad news")  # See this in GCP console if the two lines below is not run

logging.addLevelName(logging.ERROR, "ERR")
cloud_logger.error("More bad news")  # <- Crash if this and the line above is run

Output

Program shutting down, attempting to send 2 queued log entries to Stackdriver Logging...
Waiting up to 5 seconds.
Failed to submit 2 logs.
Traceback (most recent call last):
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 691, in _ConvertScalarFieldValue
    number = int(value)
ValueError: invalid literal for int() with base 10: 'ERR'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 549, in _ConvertFieldValuePair
    setattr(message, field.name, _ConvertScalarFieldValue(value, field))
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 695, in _ConvertScalarFieldValue
    value, field.enum_type.full_name))
google.protobuf.json_format.ParseError: Invalid enum value ERR for enum type google.logging.type.LogSeverity.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<my virtualenv>/lib/python3.6/site-packages/google/cloud/logging/handlers/transports/background_thread.py", line 122, in _safely_commit_batch
    batch.commit()
  File "<my virtualenv>/lib/python3.6/site-packages/google/cloud/logging/logger.py", line 383, in commit
    client.logging_api.write_entries(entries, **kwargs)
  File "<my virtualenv>/lib/python3.6/site-packages/google/cloud/logging/_gapic.py", line 125, in write_entries
    entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "<my virtualenv>/lib/python3.6/site-packages/google/cloud/logging/_gapic.py", line 125, in <listcomp>
    entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "<my virtualenv>/lib/python3.6/site-packages/google/cloud/logging/_gapic.py", line 464, in _log_entry_mapping_to_pb
    ParseDict(mapping, entry_pb)
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 421, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 452, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "<my virtualenv>/lib/python3.6/site-packages/google/protobuf/json_format.py", line 552, in _ConvertFieldValuePair
    raise ParseError('Failed to parse {0} field: {1}'.format(name, e))
google.protobuf.json_format.ParseError: Failed to parse severity field: Invalid enum value ERR for enum type google.logging.type.LogSeverity.
Sent all pending logs.

Process finished with exit code 0

@tseaver tseaver added api: logging Issues related to the Cloud Logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. api: clouddebugger Issues related to the Cloud Debugger API. labels Jan 28, 2019
@sduskis sduskis added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed api: clouddebugger Issues related to the Cloud Debugger API. labels Jun 11, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jul 29, 2019
@tseaver tseaver self-assigned this Jul 30, 2019
@tseaver
Copy link
Contributor

tseaver commented Jul 30, 2019

@josteinl Thanks for the report: I was able to reproduce the failure using your script. With the patch in #8837, the script succeeds, and both log entries are sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants