
import google.cloud.logging as glog
import logging
import contextlib
import io
import sys
import os

LOGGING_PROJECT = os.environ.get('LOGGING_PROJECT', '')

def configure(project=LOGGING_PROJECT):
    if not project:
        print('!! Error: The $LOGGING_PROJECT enviroment '
              'variable is required in order to set up cloud logging. '
              'Cloud logging is disabled.')
        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:
        print('!! Cloud logging disabled')


import google.cloud.logging as glog
import logging
import contextlib
import io
import sys
import os

LOGGING_PROJECT = os.environ.get('LOGGING_PROJECT', '')

def configure(project=LOGGING_PROJECT):
    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')

Change some errors to go to stderr.
Change some errors to go to stderr.

These non-fatal errors violated GTP protocol.

  
  import google.cloud.logging as glog
  import logging
  import contextlib
  import io
  import sys
  import os
  
  LOGGING_PROJECT = os.environ.get('LOGGING_PROJECT', '')
  
  def configure(project=LOGGING_PROJECT):
      if not project:
-         print('!! Error: The $LOGGING_PROJECT enviroment '
+         sys.stderr.write('!! Error: The $LOGGING_PROJECT enviroment '
                'variable is required in order to set up cloud logging. '
-               'Cloud logging is disabled.')
+               '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:
-         print('!! Cloud logging disabled')
+         sys.stderr.write('!! Cloud logging disabled\n')
  
Change some errors to go to stderr.
## Code Before:

import google.cloud.logging as glog
import logging
import contextlib
import io
import sys
import os

LOGGING_PROJECT = os.environ.get('LOGGING_PROJECT', '')

def configure(project=LOGGING_PROJECT):
    if not project:
        print('!! Error: The $LOGGING_PROJECT enviroment '
              'variable is required in order to set up cloud logging. '
              'Cloud logging is disabled.')
        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:
        print('!! Cloud logging disabled')

## Instruction:
Change some errors to go to stderr.
## Code After:

import google.cloud.logging as glog
import logging
import contextlib
import io
import sys
import os

LOGGING_PROJECT = os.environ.get('LOGGING_PROJECT', '')

def configure(project=LOGGING_PROJECT):
    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')
