PhoneGap:使用gwt-log进行远程日志记录

时间:2014-04-03 17:41:22

标签: java android ios gwt cordova

我在iOs PhoneGap环境中使用gwt-phonegapgwt-log

我使用gwt-log和远程日志记录工作正常。我的应用程序也在PhoneGap容器中运行。

我的web.xml配置如下:

<module rename-to='mobilePhoneGapIOS'>

<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name="com.allen_sauer.gwt.log.gwt-log-RemoteLogger" />

<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_FirebugLogger" value="DISABLED" />


<set-property name="compiler.emulatedStack" value="true" />
<set-configuration-property name="compiler.emulatedStack.recordLineNumbers" value="true"/>
<set-configuration-property name="compiler.emulatedStack.recordFileNames" value="true"/>

   ...

我的web.xml包含:

<servlet>
    <servlet-name>GWT-Log-remote-logger-Servlet</servlet-name>
    <servlet-class>test.mobilePhoneGapIOS.server.MyRemoteLoggerServlet</servlet-class>
    <init-param>
        <param-name>symbolMaps</param-name>
        <param-value>WEB-INF/deploy/mobilePhoneGapIO/symbolMaps</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>GWT-Log-remote-logger-Servlet</servlet-name>
    <url-pattern>/mobilePhoneGapIOS/gwt-log</url-pattern>
</servlet-mapping>  

我尝试记录以下异常:

Log.fatal("This is what an exception might look like", new RuntimeException("2 + 2 = 5"));

当我在桌面浏览器上使用它时,它可以正常工作,但在phonegap上它不起作用。输出是:

2014-04-03 19:20:41.202 Test[29194:907] ERROR: (-:-) 2014-04-03 19:20:41,193 [FATAL] This is what an exception might look like
java.lang.RuntimeException: 2 + 2 = 5
    at Unknown._Jb(StackTraceCreator.java:180)
    at Unknown.ixb(StackTraceCreator.java:518)
    at Unknown.gxb(Throwable.java:56)
    at Unknown.Bzb(Exception.java:29)
    at Unknown.Ezb(RuntimeException.java:29)
    at Unknown.Cc(Mobile.java:81)
    at Unknown.Fc(Mobile.java:32)
    at Unknown.FJb(SchedulerImpl.java:180)
    at Unknown.wJb(SchedulerImpl.java:345)
    at Unknown.JJb(SchedulerImpl.java:78)
    at Unknown.DJb(SchedulerImpl.java:138)
    at Unknown.TIb(Impl.java:290)
    at Unknown.XIb(Impl.java:347)
    at Unknown.anonymous(Impl.java:93)
    at Unknown.anonymous(UnloadSupport.java:42)

在Phonegap容器中使用stacktrace反混淆进行远程日志记录时,我需要更改什么?

1 个答案:

答案 0 :(得分:1)

我从未使用过gwt-log,因为官方logging mechanism in GWT对我来说一直很好。这就是我通常在项目中启用远程日志记录的方式:

首先,您必须在module.gwt.xml文件中启用日志记录和远程处理程序:

 <inherits name="com.google.gwt.logging.Logging"/>
 <set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />  

其次,您的web.xml应该像这样配置远程日志记录的url-pattern(请注意,您必须在应用程序中设置确切的模式)。

<servlet>
    <servlet-name>remoteLogging</servlet-name>
    <servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>remoteLogging</servlet-name>
    <!-- replace gwt_test with your module name -->
    <url-pattern>/gwt_test/remote_logging</url-pattern>
</servlet-mapping>

最后,像往常一样使用java记录器:

 Logger logger = Logger.getLogger("MyLoggerName");
 logger.log(Level.WARNING, "Something was wrong ", new RuntimeException("My error"));

如果您希望在服务器端对异常进行非模糊处理,则必须实现自己的servlet来激活它:

public class RemoteLoggingDeobfuscatorServlet extends RemoteLoggingServiceImpl {
  public void init() throws ServletException {
    super.init();
    // replace gwt_test with your module name
    String symbols = getServletContext().getRealPath("WEB-INF/deploy/gwt_test/symbolMaps/");
    super.setSymbolMapsDirectory(symbols);
  }
}

并更改您的web.xml

<servlet-class>your_namespace.RemoteLoggingDeobfuscatorServlet</servlet-class>