Python 3.7 - Logger not showing any log on GCP LOG Viewer

Viewed 1771

I've made a decorator named "logger" and I'm using it to show log on the console.

In my python 2.7 everything works fine but in my python 3.7 code, it doesn't print any log in GCP log viewer. (My code is deployed on GCP standard environment)

I've tried to set this code but it doesn't work.

logging.getLogger().setLevel(logging.INFO)

Here's my simple logger decorator

def logger(func):
  def wrapper(*args, **kwargs):
    logging.info('INSIDE %s PARAMETERS: %s', func.__name__, args)
    res = func(*args, **kwargs)
    logging.info('OUTSIDE %s OUTPUT: %s', func.__name__, res)
    return res

  return wrapper

Even a simple logging.info statement is not working.

I've tried everything with logging, but nothing gets printed out on GCP Log Viewer.

logging.info("Text info")
logging.debug("Text debug")
logging.warning("Text warning")
logging.error("Text error")
logging.critical("Text critical")

Here is the log viewer

Screen shot of log viewer

1 Answers

I deployed the following app to App Engine:

In app.yaml:

runtime: python37

In requirements.txt:

Flask==1.0.2

In main.py:

from flask import Flask

import logging
logging.getLogger().setLevel(logging.INFO)

app = Flask(__name__)

@app.route('/')
def hello():
    logging.info("Text info")
    logging.debug("Text debug")
    logging.warning("Text warning")
    logging.error("Text error")
    logging.critical("Text critical")
    return 'Hello World!'

When I look at the Stackdriver logs for the application after a request, I see the INFO, WARNING, ERROR and CRITICAL log messages as expected.

Is it possible you're looking somewhere else for the logs? From the App Engine Dashboard, you can go to

Services > [your service] > Diagnose > Tools > Logs

to find the logs for your service.

Related