Skip to content

Instantly share code, notes, and snippets.

@daspecster
Created March 28, 2017 15:23
Show Gist options
  • Save daspecster/616fadeadfeb904c9892a33dc9f7bbf3 to your computer and use it in GitHub Desktop.
Save daspecster/616fadeadfeb904c9892a33dc9f7bbf3 to your computer and use it in GitHub Desktop.
Logging Snippets Results
# import logging
# import google.cloud.logging # Don't conflict with standard logging
# from google.cloud.logging.handlers import CloudLoggingHandler
# client = google.cloud.logging.Client()
# handler = CloudLoggingHandler(client)
# cloud_logger = logging.getLogger('cloudLogger')
# cloud_logger.setLevel(logging.INFO) # defaults to WARN
# cloud_logger.addHandler(handler)
# cloud_logger.error('bad news')
"""
Output:
In the console under "global" I see "bad news" logging entries.
"""
# import logging
# import google.cloud.logging # Don't conflict with standard logging
# from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
# client = google.cloud.logging.Client()
# handler = CloudLoggingHandler(client, name="mycustomlog")
# logging.getLogger().setLevel(logging.INFO) # defaults to WARN
# setup_logging(handler, excluded_loggers=('werkzeug',))
# logging.error('bad news')
"""
Output:
In the console under "global" I see "bad news" logging entries.
Also in STDOUT
"""
# import logging
# import google.cloud.logging
# from google.cloud.logging.handlers import CloudLoggingHandler
#
# client = google.cloud.logging.Client()
# handler = CloudLoggingHandler(client)
#
# cloud_logger = logging.getLogger('cloudLogger')
# cloud_logger.setLevel(logging.INFO)
# cloud_logger.addHandler(handler)
#
# cloud_logger.error('bad news') # API call
"""
Output:
In the console under "global" I see "bad news" logging entries.
"""
import logging
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
client = google.cloud.logging.Client()
handler = CloudLoggingHandler(client)
google.cloud.logging.handlers.setup_logging(handler)
logging.getLogger().setLevel(logging.DEBUG)
logging.error('bad news') # API call
"""
Output:
bad news
Making request: POST https://accounts.google.com/o/oauth2/token
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment