我想使用 deobfuscate 选项配置远程日志服务。我知道默认情况下符号映射是在/WEB-INF/deploy/MODULNAME/symbolMaps 文件夹中生成的,并且 GWT 远程记录器实现(RemoteLoggingServiceImpl)使用 StackTraceDeobfuscator,它需要符号映射目录才能工作。我认为 RemoteLoggingServiceImpl 应该自动设置正确的路径到 symbolMaps 目录,但在 Debug模式下我发现 setSymbolMapsDirectory 方法没有在 RemoteLoggingServiceImpl 上调用。为了解决这个问题,我使用“代理”手动调用该方法:

public class ConfigurableRemoteLoggingServiceImpl extends RemoteLoggingServiceImpl {

@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);

    final String symbolMapsDirectory = config.getInitParameter("symbolMapsDirectory");
    setSymbolMapsDirectory(symbolMapsDirectory);
}
}

并在 web.xml
<servlet>
        <servlet-name>remoteLogging</servlet-name>
        <servlet-class>pl.dandelite.empik.sdl.manager.server.service.ConfigurableRemoteLoggingServiceImpl</servlet-class>

        <init-param>
          <param-name>symbolMapsDirectory</param-name>
          <param-value>C:/symbolMaps</param-value>
      </init-param>
</servlet>
<servlet-mapping>
        <servlet-name>remoteLogging</servlet-name>
        <url-pattern>/sdlconsole/remote_logging</url-pattern>
</servlet-mapping>

并在编译期间使用 -extra 参数定义目录

此解决方案有效,但仅当我将绝对路径设置为symbolMaps 目录时,才有点不切实际;)

现在我的问题是:在 Tomcat 上使用 StackTraceDeobfuscator 配置 RemoteLoggingServiceImpl 的正确方法是什么?

最佳答案

这是我设置符号目录的方法:

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // Synchronized so that in a multi-module deployment, there are no conflicts.
    synchronized (RemoteLoggingServiceImpl.class) {
        // Initialize SLF$j bridge logging to redirect jul logs to slf4j. We remove any
        // default loggers to ensure logging doesn't happen to stdout or stderr.
        java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
        Handler[] handlers = rootLogger.getHandlers();
        for (Handler handler : handlers) {
            rootLogger.removeHandler(handler);
        }
        SLF4JBridgeHandler.install();
    }

    String moduleName = config.getInitParameter("module.name");
    if (StringUtils.isBlank(moduleName)) {
        _logger.error("No module name defined. Please set the module.name servlet init "
                + "parameter to point to the GWT module and enable extra symbolMaps at "
                + "/extra/<module name>/symbolMaps in the servlet context to facilitate "
                + "deobfuscation of stack traces.");
    } else {
        String path = config.getServletContext().getRealPath(
                "/WEB-INF/deploy/" + moduleName + "/symbolMaps/");

        if (path != null) {
            setSymbolMapsDirectory(path);
        }
    } // end else.
}

关于java - 如何在Tomcat下配置GWT stacktrace deobfuscator?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14159416/

10-11 19:22