Logging in a Google Cloud Endpoint - google-app-engine

I need to debug my Google Cloud Endpoint after it is deployed to AppEngine. I am trying to write entries to the log but they never show up in the log viewer on the Google Developers Console. Here is the logging code I created in Android Studio:
import java.util.logging.Logger;
...
public class MyEndpoint {
private static final Logger log = Logger.getLogger(MyEndpoint.class.getName());
...
log.info("message to log");
This code executes in the cloud without error but nothing shows up in the log. What am I doing wrong?

The entry is not showing in the log because the default logging level in app engine is: WARNING. Setting the logging level prior to calling log.info() caused the log entry to show in the console as expected. Here is the revised code with setLevel in context:
import java.util.logging.Logger;
...
public class MyEndpoint {
private static final Logger log =Logger.getLogger(MyEndpoint.class.getName());
...
log.setLevel(Level.INFO);
log.info("message to log");

Related

Spring Boot App Engine log messages not showing

I have a Spring Boot application that I am deploying to an App Engine standard environment using Java 8. I cannot seem to get log messages to show in the log viewer in my cloud console. I do have other logs working such as the endpoint being hit.
logging.properties:
.level = FINEST
appengine-web.xml:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<service>logging-service</service>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
Spring Controller:
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
#RestController
#RequestMapping("/log")
public class LogSubscription {
private static final Logger log = Logger.getLogger(LogSubscription.class.getName());
#RequestMapping(method = GET)
public String logSomething() {
log.log(Level.INFO, "Should see this in the console");
log.log(Level.SEVERE, "This is severe");
log.info("Normal Log Message");
return "Should log successfully";
}
}
Logging to the console works perfectly fine when I run locally. I just can't see the logs in the web console. I can see the GET request but not the logging in it. I am attaching a screenshot of my log.
I was finally able to find a solution. You must add the following to the build.gradle file:
configurations {
compile.exclude group: "org.slf4j", module: "jul-to-slf4j"
}

Updating index.android.bundle from remote server in react native [Android]

I am creating a demo react native app that is implementing aeroFS https://github.com/redbooth/react-native-auto-updater library
[An aerofs library is nothing but each time when app opens it will check for update from remote server and if update is available it will download and ask the user to apply for the update without play store].
So far the app is able to download the file but after download i am not able to see any changes in the app.I'm sure the newly downloaded bundle is not used in the activity.
On further checking inside the library i found the following method in ReactNativeAutoUpdaterActivity class (main class):-
#Override
#Nullable
public String getJSBundleFile() {
updater=ReactNativeAutoUpdater.getInstance(this.getApplicationContext());
updater.setMetadataAssetName(this.getMetadataAssetName());
return updater.getLatestJSCodeLocation();
}
The ReactNativeAutoUpdaterActivity extends from ReactActivity which does not have this method.I think this is moved to ReactNativeHost so i knew this is the problem but now should i implement my own react native host class to over ride the method so that once new bundle file is downloaded i can apply it to app.
MainApplication.java
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
.
.
.
#Override
public void onCreate(){
super.onCreate();
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
preferences.edit().putString("debug_http_host", "128.xxx.xxx.xxx:1234").apply();
}
When using a remote VM, port 8081 is not exposed, so:
npm start -- --reset-cache --port=1234
AppDelegate.m (iOS):
jsCodeLocation = [NSURL URLWithString:#"http://128.xxx.xxx.xxx:1234/index.js"];

Google App Engine does not recognized #Named parameter

I am using the Google Plugin for Eclipse, and I am writing an App Engine app as a Dynamic Web Module in Eclipse WTP.
I have defined the following Java class to serve as a Cloud Endpoint API:
package mypackage;
import static mypackage.OfyService.ofy;
import java.util.List;
import java.util.logging.Logger;
import mypackage.models.ProbeEntry;
import mypackage.models.ProbeSet;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.config.Named;
import com.googlecode.objectify.ObjectifyService;
#Api(name = "analysisEndpoint",
version = "v1",
namespace = #ApiNamespace(
ownerDomain = "myorg",
ownerName = "myorg",
packagePath = "analysis")
)
public class AnalysisEndpoint {
private static final Logger logger = Logger.getLogger(AnalysisEndpoint.class.getName());
#ApiMethod(name = "getMyProbeEntries", httpMethod = ApiMethod.HttpMethod.GET)
public ProbeSet getMyProbeEntries(#Named("amount") int amount) {
ObjectifyService.begin();
List<ProbeEntry> probeList = ofy().load().type(ProbeEntry.class).limit(amount).list();
return new ProbeSet(probeList);
}
}
I attempt to deploy to the Google App Engine by right-clicking the project -> Google App Engine WTP -> Deploy Project to Remote Server. I see in my console that the project is compiling and uploading, but eventually errors out with:
99% Endpoints configuration not updated. The app returned an error when the Google Cloud Endpoints server attempted to communicate with it.
The error log on the app engine shows the following:
18:31:58.119
javax.servlet.ServletContext log: unavailable
com.google.api.server.spi.config.validation.MissingParameterNameException: analysisEndpoint.myorg.analysis.AnalysisEndpoint.getMyProbeEntries parameter (type int): Missing parameter name. Parameter type (int) is not an entity type and thus should be annotated with #Named.
at
com.google.api.server.spi.config.validation.ApiConfigValidator.validateApiParameter(ApiConfigValidator.java:214)
...
As can be seen in the code, I do have #Named("amount") before the offending parameter. What is going wrong here? Side note: If I simply remove the amount parameter, the project deploys to App Engine without a problem.
Any help would be greatly appreciated.

Access remote service using GWTP Rest Dispatch

I want to separate packages for UI and backend development of my GWTP app.
Currently my UI access the backend using Rest dispatch configured like this:
bindConstant().annotatedWith(RestApplicationPath.class).to("/MyProject/api");
I want to access remote service using localhost UI (running GWT app using eclipse plugin). I changed the above line to:
bindConstant().annotatedWith(RestApplicationPath.class).to("http://my-app.appspot.com/MyProject/api");
Using this, call successfully reaches server ( I can see this in appengine logs) but UI always gets back status code 0.
What is wrong with above setup? Do I have to do something else to access remote service using GWT ui ?
If you want to have a solution that works both on localhost/App Engine, you'd want to use something like this:
import com.google.gwt.core.client.GWT;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.gwtplatform.dispatch.rest.client.RestApplicationPath;
import com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule;
public class ServiceModule extends AbstractGinModule {
#Override
protected void configure() {
install(new RestDispatchAsyncModule.Builder().build());
}
#Provides
#RestApplicationPath
String getApplicationPath() {
String baseUrl = GWT.getHostPageBaseURL();
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}
return baseUrl + "/MyProject/api";
}
}
The string returned by getApplicationPath will be bound to #RestApplicationPath and used seamlessly by GWTP's RestDispatch.
In your case, the string will resolve to http://localhost:8080/MyProject/api or "http://my-app.appspot.com/MyProject/api" depending on the app running locally or on App Engine.

GWT deploy to google App Engine get a 404 error

I'm trying to learn how to deploy an GWT application to Google App Engine.
I'm using GWT 2.4 + eclipse with Java 7.
I have basically a static page with a button that doesn't do anything.
public class Test1 implements EntryPoint {
public void onModuleLoad() {
final Button sendButton = new Button("Send");
RootPanel.get().add(sendButton);
}
}
I have created my application istoeumtestedenome, and in localhost it works. I have deployed it to App Engine with no errors. But when I try to access the page http://istoeumtestedenome.appspot.com/, a 404 error is displayed.
What can I do?
There are many things that could have gone wrong. The first things that come to mind:
Your static HTML file (host page) is in the wrong place (folder).
You did not specify a welcome page - or there are some other problems - in your web.xml file.
Go to your Admin Console for App Engine, and click on the logs to see what goes wrong.

Resources