java-GWT远程日志记录无法记录Throwable Stacktrace?
作者:互联网
我想使用GWTRemote Logging.这是我做的:
在我的web.xml文件中,我做了:
<servlet>
<servlet-name>remoteLogging</servlet-name>
<servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogging</servlet-name>
<url-pattern>/web/remote_logging</url-pattern>
</servlet-mapping>
在我的gwt.xml文件中,我做了:
<module rename-to='web'>
...
<inherits name="com.google.gwt.logging.Logging" />
<set-property name="gwt.logging.logLevel" value="INFO" />
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
<set-property name="gwt.logging.developmentModeHandler" value="ENABLED" />
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
在我的GWT Java代码中的某处我做了:
Logger logger = Logger.getLogger("NameOfYourLogger");
logger.log(Level.SEVERE, "this message should get logged");
但是,当我尝试像这样记录堆栈跟踪(Throwable)时:
// Throwable throwable
LogRecord lr = new LogRecord(Level.SEVERE, "test");
lr.setThrown(throwable);
logger.log(lr);
我收到一个错误:
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)
如何远程记录stacktrace?
编辑:我也试过
// Throwable throwable
LogRecord lr = new LogRecord(Level.SEVERE, throwable.toString());
logger.log(lr);
和
// Throwable throwable
LogRecord lr = new LogRecord(Level.SEVERE, throwable.getMessage());
logger.log(lr);
但出现以下错误:
| 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
->> 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
->> 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
编辑:
这是我使用的代码:
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
new AsyncCallback<GetResults<ItemDto>>() {
@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);
}
...
}
解决方法:
考虑记录异常堆栈跟踪:
<set-property name="compiler.stackMode"
value="emulated" />
<set-configuration-property name="compiler.emulatedStack.recordLineNumbers"
value="true"/>
<set-configuration-property name="compiler.emulatedStack.recordFileNames"
value="true"/>
stacktrace和异常处理如下:
> http://www.summa-tech.com/blog/2012/06/11/7-tips-for-exception-handling-in-gwt/
> https://code.google.com/p/google-web-toolkit/wiki/WebModeExceptions
标签:grails,servlets,javascript,java,gwt 来源: https://codeday.me/bug/20191122/2057359.html