1
votes

I'm trying to see the difference between default flask logger and stackdriver logger in GAE's sample application: https://cloud.google.com/python/getting-started/using-pub-sub

Code without StackDriver logger:

def create_app(config, debug=False, testing=False, config_overrides=None):
    app = Flask(__name__)
    app.config.from_object(config)

    app.debug = debug
    app.testing = testing

    if config_overrides:
        app.config.update(config_overrides)

    # Configure logging
    if not app.testing:
        logging.basicConfig(level=logging.INFO)

Code with StackDriver logger:

def create_app(config, debug=False, testing=False, config_overrides=None):
    app = Flask(__name__)
    app.config.from_object(config)

    app.debug = debug
    app.testing = testing

    if config_overrides:
        app.config.update(config_overrides)

    # [START setup_logging]
    if not app.testing:
        client = google.cloud.logging.Client(app.config['PROJECT_ID'])
        # Attaches a Google Stackdriver logging handler to the root logger
        client.setup_logging(logging.INFO)

There's some difference with the StackDriver code where a logger was imported from google cloud. However, the output of the logs seems similar:

Output Log without StackDriver: enter image description here

Output Log with StackDriver:

enter image description here

These logs does not look that different with or without a StackDriver.

When I go to the StackDriver logs I get redirected to the default logs in GAE. Is there anything special with StackDriver loggers that the normal flask logger cannot do?

1
Since you filtered logs at INFO level and I see two different logs in "Any log" level in the screenshots... I'm not sure what is the difference you want to know. What you see in the screenshot is the normal Log Entry for Stackdriver Logging - enle lin

1 Answers

1
votes

Taking a look into the the two function that you are using for logger configuration: Basicconfig and Setup.logging, your loggers have similar settings so it make sense to me to have similar log output.

I didn't understand what you expected to see in Stackdriver Logging Viewer since the two pictures that you attached looks right to me since them are normal Log entry for Stackdriver Logging. Notice that, by default, App Engine logging is provided by Stackdriver Logging as explained in this document

The advantage of Stackdriver Logging is to have a better management of the logs and the possibility to analyze them. You can have a look in this tutorial in order to have an idea about it.