1

I have a simple service in GCP Flex:

import logging
from flask import Flask
app = Flask(__name__)

logging.basicConfig(level=logging.DEBUG)

@app.route('/hello')
def hello():
    logging.debug('hello')
    return 'hello'

Looking at Stackdriver this log is shown in stderr, like this:

15:32:38.000 DEBUG:root:hello

A couple of problems with this:

  • timestamps should have milisecond precision (always .000)
  • logs cannot be filtered using stackdriver log level filter

Is there any way to address these issues? Does logging need to be configured in some way?

zoran119
  • 10,657
  • 12
  • 46
  • 88

1 Answers1

-1

If you need to see logs in stackdriver just use print (in Python) or System.out.print(java) command in your code. It will appear in the Stackdriver.

eg: print ("hello") or

System.out.println("hello");

And the time stamp is in Zulu format. (eg: timestamp: "2018-07-18T10:16:46Z").

you can get an idea by referring this.

Kirill Bulygin
  • 3,658
  • 1
  • 17
  • 23
  • I downvoted because using the logging module is better than using print and `System.out.println` is java not python I recommend this article https://medium.com/retailmenot-engineering/formatting-python-logs-for-stackdriver-5a5ddd80761c for better Stackdriver integration – firescar96 Mar 25 '19 at 15:01
  • Print examples are given for both python & java. AND when this answer is posted (in 2018) Stackdriver had a bug. At that time if you wanted to filter out the logs, You had to do that way. Now that is fixed. @firescar96 – Sachith.Wanni Dec 12 '20 at 05:41