title: GWT Remote Logging could not log Throwable Stacktrace?
body: <p>I want to use GWT <a href="http://www.gwtproject.org/doc/latest/DevGuideLogging.html" rel="nofollow">Remote Logging</a>. This is what I did: </p>
  
  <p>In my web.xml file I did:</p>
  
  <pre><code>&lt;servlet&gt;
          &lt;servlet-name&gt;remoteLogging&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.google.gwt.logging.server.RemoteLoggingServiceImpl&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;remoteLogging&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/web/remote_logging&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt; 
  </code></pre>
  
  <p>In my gwt.xml file I did:</p>
  
  <pre><code> &lt;module rename-to='web'&gt;
  
   ...    
  
   &lt;inherits name="com.google.gwt.logging.Logging" /&gt;
      &lt;set-property name="gwt.logging.logLevel" value="INFO" /&gt;
      &lt;set-property name="gwt.logging.enabled" value="TRUE" /&gt;
      &lt;set-property name="gwt.logging.popupHandler" value="DISABLED" /&gt;
      &lt;set-property name="gwt.logging.developmentModeHandler" value="ENABLED" /&gt;  
      &lt;set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" /&gt;
  </code></pre>
  
  <p>And somewhere in my GWT Java code I did:</p>
  
  <pre><code>Logger logger = Logger.getLogger("NameOfYourLogger");
  logger.log(Level.SEVERE, "this message should get logged");
  </code></pre>
  
  <p>But, when I try to log the stack trace (Throwable) like this: </p>
  
  <pre><code>// Throwable throwable
  
  LogRecord lr = new LogRecord(Level.SEVERE, "test");
  lr.setThrown(throwable);
  logger.log(lr);
  </code></pre>
  
  <p>I get an error: </p>
  
  <pre><code>16:24:26.887 [ERROR] [web] Sun Feb 09 16:24:26 CET 2014 WireActivityLogger
  SEVERE: Remote logging failed: 
  com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: java.lang.ClassCastException: com.google.gwt.core.client.impl.SerializableThrowable cannot be cast to com.google.gwt.core.shared.SerializableThrowable
      at com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException_FieldSerializer.instantiate(IncompatibleRemoteServiceException_FieldSerializer.java:16)
      at com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException_FieldSerializer.create(IncompatibleRemoteServiceException_FieldSerializer.java:25)
      at com.google.gwt.user.client.rpc.impl.SerializerBase.instantiate(SerializerBase.java:115)
      at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader.deserialize(ClientSerializationStreamReader.java:396)
      at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamReader.readObject(AbstractSerializationStreamReader.java:119)
      at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:216)
      at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
      at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
      at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
      at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
      at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
      at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
      at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
      at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
      at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
      at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
      at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
      at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
      at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
      at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
      at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
      at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
      at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
      at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
      at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p><strong>How can I remote log the stacktrace?</strong></p>
  
  <p>Edit: I also tried </p>
  
  <pre><code>// Throwable throwable
  LogRecord lr = new LogRecord(Level.SEVERE, throwable.toString());
  logger.log(lr);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>// Throwable throwable
  LogRecord lr = new LogRecord(Level.SEVERE, throwable.getMessage());
  logger.log(lr);
  </code></pre>
  
  <p>but I got the following error:</p>
  
  <pre><code>| Error 2014-02-19 02:21:04,017 [http-nio-8080-exec-7] ERROR [localhost].[/test]  - Exception while dispatching incoming RPC call
  Message: Service method 'public abstract java.lang.String com.google.gwt.logging.shared.RemoteLoggingService.logOnServer(java.util.logging.LogRecord)' threw an unexpected exception: java.lang.NullPointerException
      Line | Method
  -&gt;&gt;  389 | encodeResponseForFailure in com.google.gwt.user.server.rpc.RPC
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  |    579 | invokeAndEncodeResponse  in     ''
  |    265 | processCall . . . . . .  in com.google.gwt.user.server.rpc.RemoteServiceServlet
  |    305 | processPost              in     ''
  |     62 | doPost . . . . . . . . . in com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
  |     46 | doFilterInternal         in org.grails.jaxrs.web.JaxrsFilter
  |     70 | doFilter . . . . . . . . in com.github.greengerong.PreRenderSEOFilter
  |   1145 | runWorker                in java.util.concurrent.ThreadPoolExecutor
  |    615 | run . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
  ^    722 | run                      in java.lang.Thread
  Caused by NullPointerException: null
  -&gt;&gt;  262 | hash                     in java.util.Hashtable
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  |    459 | get                      in     ''
  |    489 | findLogger . . . . . . . in java.util.logging.LogManager$LoggerContext
  |    910 | getLogger                in java.util.logging.LogManager
  |    400 | demandLogger . . . . . . in     ''
  |    317 | demandLogger             in java.util.logging.Logger
  |    361 | getLogger . . . . . . .  in     ''
  |     62 | logOnServer              in com.google.gwt.logging.server.RemoteLoggingServiceUtil
  |     46 | logOnServer . . . . . .  in com.google.gwt.logging.server.RemoteLoggingServiceImpl
  |    561 | invokeAndEncodeResponse  in com.google.gwt.user.server.rpc.RPC
  |    265 | processCall . . . . . .  in com.google.gwt.user.server.rpc.RemoteServiceServlet
  |    305 | processPost              in     ''
  |     62 | doPost . . . . . . . . . in com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
  |     46 | doFilterInternal         in org.grails.jaxrs.web.JaxrsFilter
  |     70 | doFilter . . . . . . . . in com.github.greengerong.PreRenderSEOFilter
  |   1145 | runWorker                in java.util.concurrent.ThreadPoolExecutor
  |    615 | run . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
  ^    722 | run                      in java.lang.Thread
  </code></pre>
  
  <p>Edit: </p>
  
  <p>This is my code that I use: </p>
  
  <pre><code>import java.util.logging.Level;
  import java.util.logging.LogRecord;
  import java.util.logging.Logger;
  
  new AsyncCallback&lt;GetResults&lt;ItemDto&gt;&gt;() {
  
  
              @Override
              public void onFailure(Throwable e) {
                  Logger logger = Logger.getLogger("test");
                  logger.log(Level.SEVERE, "this message should get logged");
  
                  LogRecord lr = new LogRecord(Level.SEVERE, e.toString());
                  logger.log(lr);
  
              }
  
              ...
  
  }
  </code></pre>