Google App Engine - Console Output - google-app-engine

I am running a Java Microengine on GAE.
I have my own html pages for data input and output. When there is a data error and the engine cannot complete its execution (crashes) - the microengine spits out the "Response" as Server not available, please try later.
In order to debug, I run the dataset in the dev environment - as a Java application to identify the error in the console output.
Is there a way to capture the "error" (the console output equivalent when run as a Java application) - as an output string and send it as a content of the servlet response from the deployed Application in GAE..
thanks,

assuming you are using App Engine Managed VM, and a logging framework, you should also forward the log entry into a file, e.g. /var/log/app_engine/custom_logs/app.log
https://cloud.google.com/appengine/docs/managed-vms/custom-runtimes#logging
Subsequently, you'll be able to read the output from Google Cloud Logging.

Related

AppEngine get/view logs

I run my application in AppEngine (Java).
I want to use gcloud app logs command to view my application logs:
gcloud app logs tail
However, the output is just few data as below:
....
2019-10-04 12:46:43 default[api-v1-0-0] "GET / HTTP/1.1" 200
2019-10-04 12:46:43 default[api-v1-0-0] "GET / HTTP/1.1" 200
....
Actually, I expect gcloud app logs will show logs that my application printed to stdout and stderr. However, it does not.
My question is: How to get/view application stdout/stderr logs by using gcloud command?
From gcloud app logs tail:
DESCRIPTION
Streams logs for App Engine apps.
The command is designed as a blocking call primarily watching for the app logs being generated after the command is invoked (though at startup it may also display a few historical logs, generated before the command is issued).
To focus primarily on the historical logs you want to use the gcloud app logs read command:
DESCRIPTION
Display the latest log entries from stdout, stderr and crash log for
the current Google App Engine app in a human readable format.
Note that the presence of the stdout/stderr in the logs depends on the environment and runtime your app uses. For example in the 1st generation standard environment (at least for the python runtime) the messages printed directly to stdout/stderr do not show up in the logs, one has to specifically use the python logging calls.
I suspect the same might be true for Java, as I see stdout/stderr mentioned in the logging docs for Java11 (and flex environment), but not in the Java8 one.
I also could not use
> gcloud app logs tail
but i found out you can use:
gcloud logging logs list
This will return a list of log names like:
NAME
projects/intan1/logs/appengine.googleapis.com%2Frequest_log
projects/intan1/logs/cloudaudit.googleapis.com%2Factivity
Then you can call:
gcloud beta logging read logName=projects/intan1/logs/appengine.googleapis.com%2Frequest_log
This will return a log, with a lot of extra info, but maybe this can help you!

Getting "/dev/log" in the "gcloud app logs tail" stream

In the browser cloud console for my Google App Engine app, I can choose to see the logs for /dev/log and stderr which gives me all of the log entries that I'm expecting to see.
However, when I use the command line gcloud app logs tail to stream the logs in my terminal, I can't get it to give me the /dev/log entries.
The docs say the default list of logs include: stderr,stdout,crash.log,nginx.request,request_log
So the /dev/log must be represented by some other identifier, but I can't find any docs on what it might be. I've tried a few guesses, but none work.
How can I can the terminal to stream the same logs I'm getting in my browser?
You can use command like gcloud logging read to interact with Stackdriver logging & get a non streamed version of those logs. Setup the Stackdriver GUI with the logs you wish to see, then convert to an advanced filter. You can then paste the advanced filter as is, in quotations after gcloud logging read. Examples in gcloud logging read documentation. I will get back to you in a comment on this post as to whether you can get the /dev/log logs with the gcloud app logs tail command. I will update on Saturday

Java Google AppEngine Managed VMs: What logs are obtainable through the Logging API?

I like that I can use the Logs API (described here: https://cloud.google.com/appengine/docs/java/logs/) to programatically access and display app & request logs as I see fit--it's great.
Now that I'm using Managed VMs on AppEngine you can see on the Admin Console Logs Viewer that there are a ton of additional logs--including in my case a custom log which I found I could include in the viewer (decribed here: https://cloud.google.com/appengine/docs/managed-vms/custom-runtimes#logging).
My question is: Is there any way I can use the Logs API (or other pipelines already built?) to access these logs? My Managed VM module includes several components which could produce logs that I want to view:
App logs -- I can get these! No problem here.
Custom log files created by background processes I kick off in _ah/start (like "my_custom_1.log" in the screenshot)
STDERR & STDOUT from my background processes
Relevant Managed VM logs (e.g. for when an instance was restarted due to bad health... other system events like normal restarts?)
Basically I want "the total picture" at the instance level. Anyone tried to tame Managed VMs in this way with success? I'm not looking forward to rolling my own solution. And I wouldn't even know where to start on the problem of capturing STDERR and STDOUT. Any help appreciated.
There is a difference between App Engine logging and Google Cloud logging. Some of the Managed VM logs go to both, but much of it only goes to cloud logging.
Until recently there was not an API to read Cloud logs, only to write them. However, there is a new v2 beta API: https://cloud.google.com/logging/docs/api/introduction_v2
To do things at an instance level, entries in Cloud logging should have metadata set to denote which VM they came from. Both of these values seem to vary on logs from my VMs:
compute.googleapis.com/resource_name
compute.googleapis.com/resource_id

Registration with Endpoints Server...FAILED! (emulator worked, phone doesn't)

Code generated by Android Studio>tools>Google Cloud Tools> Generate App Engine Backend
and Generate Endpoint worked in the Emulator,
Intent intent = new Intent(this, RegisterActivity.class);
startActivity(intent);
however I got this error (image from another person's question)
http://i.stack.imgur.com/230G2.png
when I load the app onto my phone and run. (I did change the LOCAL_ANDROID_RUN to false)
The error implies that there is some Endpoint server running at http://10.0.2.2:8080
which I don't expect because I don't really understand where the Endpoint Service runs. Does it run locally on the phone or somewhere on the Cloud?
I believe generated App Engine code is shipped up to Google through the Maven appengine:update
What am I missing here, thanks
-a
UPDATE (11:24 AM)
executed:
Android Studio>tools>Google Cloud Tools> Generate Client Libraries
which added to -AppEngine/target/generated-sources/appengine-endpoints etc
This changed what happened on the phone. There is still a registration error but now says:
2) registration with Endpoints Server...FAILED!
Unable to register your device with your Cloud Endpoints server running at https://.appspot.com/_ah/api
UPDATE (11:44 AM)
executed maven script
appengine:update to get the AppEngine deployed with the new code from Generate Client Libraries
same error on phone (unable to register your device with your Cloud Endpoints server)
UPDATE (1:39 pm)
got logcat info while running app on the phone, hooked up through USB to computer,
looks like a 404 Not Found error (???)
12-27 13:36:51.942 609-703/? I/InputDispatcher﹕ Delivering touch to: action: 0x1
12-27 13:36:52.412 19103-19103/sic.example.db7 W/AbstractGoogleClient﹕ Application name is not set. Call Builder#setApplicationName.
12-27 13:36:52.412 19103-19246/sic.example.db7 E/GCMRegistrar﹕ internal error: retry receiver class not set yet
12-27 13:36:53.253 19103-19246/sic.example.db7 E/sic.example.db7.GCMIntentService﹕ Exception received when attempting to register with server at https://core-phoenix-441.appspot.com/_ah/api/
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
Not Found
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1042)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at sic.example.db7.GCMIntentService.onRegistered(GCMIntentService.java:158)
at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:296)
at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:197)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:61)
the emulator can access because it runs locally, your phone doesn't have access to the computer localhost. To do that you can check Codiak answer.
https://stackoverflow.com/a/16097253/1368396

How do I see debug log in local App Engine instance

AppEngine tutorial
http://code.google.com/appengine/docs/java/gettingstarted/usingjsps.html
suggests that the debug logs generated by java.util.logging.Logger can be seen at admin console.
However I don't see the log information from admin console for local instance at http://localhost:8888/_ah/admin
Is there a way to see debug log when developing locally?
Thanks
I see them appearing in the terminal where I start the development server.
You can set:
.level = ALL
In your logging.properties file. See http://code.google.com/appengine/docs/java/runtime.html#Logging for info on how to set up this file.

Resources