Structured logging in Java standard enviornment

230 views
Skip to first unread message

Kishu Agarwal

unread,
Oct 24, 2018, 5:49:45 AM10/24/18
to Google App Engine
I want to log json data in my logs. I have tried the steps mentioned here but still when I see my logs, all the log statements done using Logging doesn't show up there.

Any help there?

Mohammad I (Cloud Platform Support)

unread,
Oct 25, 2018, 7:58:52 PM10/25/18
to Google App Engine

Hello Kishu,


Please kindly note that the article that you provided does not have examples of structured logging. You can look into these documents instead for Structured Logging explanation and for an example on how to write structured logs. For more information on different payload formats please look into this document LogEntry. That being said, please use jsonPayload instead of StringPayload in order to log JSON data into your logs in Stackdriver Logging.


Kishu Agarwal

unread,
Oct 26, 2018, 2:12:54 AM10/26/18
to Google App Engine
Thanks Mohammad for the reply.  The link I shared did contain a example of using the stackdriver logging library. Instead of StringPayload, I have used JsonPayload only, but still I don't see anything in my logs.

I want to clarify one doubt. Is structured logging possible in standard environment? Because when I see my logs, I see logLines instead of logEntry objects.

Harmit Rishi (Cloud Platform Support)

unread,
Oct 31, 2018, 3:30:59 PM10/31/18
to Google App Engine

Hello Kishu,


I would like to confirm that you are using the example outlined in your initial link and have replaced StringPayload with JsonPayload?


If that is the case, it would be my recommendation to utilise the actual JsonPayload code offered here instead. The code from your original post is appropriate for StringPayload as JsonPayload requires its own specific import. You can find the imports required for this at the following example offered on GitHub.


However, I am still unsure of what you are trying to achieve. Stackdriver logging for Standard produces the following logs:


Request Logs- records requests that are sent to all App engine Apps (Type: Request Log).

App Logs- record activity within the App Engine app (Type: LogLine).

Third-party package logs- package logs that are included in Logs Viewer.


Based on this provided information, I would like to know where you intend these logs to go. (i.e: Request Logs or App logs specifically). You had mentioned you are seeing LogLines. I am assuming you are trying to publish logs within App Logs at this point.

If that is the case then it would be my recommendation to follow the guidelines expressed here for writing application logs. Note: you will notice that the guide mentions the import of the Java.Util library which is different than the cloud import required for Request logs.


As for your last question of “is structured logging possible in standard environment?”. I would like to inform you that JsonPayload is essentially Structured Logging. However if this not what you are expecting then I would have to request an example of what you want the log to look like.


Reply all
Reply to author
Forward
0 new messages