Log4j2打包桌面应用后无法输出调用文件及行号求助
Log4j2打包后日志丢失文件及行号问题
IDE运行时日志输出正常:
12-13-2023 15:20:49,443 -0500 [JavaFX Application Thread] WARN (LineChartController.java:797) - Please verify debug log format and serial data integrity.
但Maven生成桌面应用后,日志无法正确显示调用文件及行号:
12-13-2023 15:20:49,443 -0500 [JavaFX Application Thread] WARN (null:-1) - Please verify debug log format and serial data integrity.
当前Log4j2配置文件
<?xml version="1.0" encoding="UTF-8"?> <configuration status="DEBUG"> <Properties> <Property name="basePath">c:/temp/logs</Property> </Properties> <Loggers> <AsyncLogger name="com" level="DEBUG" additivity="false" includeLocation="true"> <AppenderRef ref="LogToRollingFile"/> </AsyncLogger> </Loggers> <Appenders> <RollingRandomAccessFile name="LogToRollingFile" filename="${basePath}/STAG.log" filepattern="${basePath}/STAG_%d{yyyyMMdd}.log.gz" immediateFlush="false"> <PatternLayout pattern="%d{MM-dd-yyyy HH:mm:ss,SSS} %d{Z} [%t] %-5p (%F:%L) - %m%n"/> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="10 MB"/> </Policies> <DefaultRolloverStrategy max="5"/> </RollingRandomAccessFile> </Appenders> </configuration>
已尝试的无效解决方案
- 在
AsyncLogger中添加includeLocation="true",问题未解决 - 配置Maven编译插件保留调试信息,无效:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>17</release> <debug>true</debug> <debuglevel>lines,vars,source</debuglevel> </configuration> </plugin>
类文件行号验证结果
对类文件执行javap -l,结果显示包含行号表:
Compiled from "LineChartController.java" public class com.americantraction.gui.LineChartController { protected static int numSignals; protected static java.util.List<java.lang.String> columnNames; protected static javafx.collections.ObservableList<com.americantraction.data.serial.DebugData> filteredDebugDataList; protected static java.lang.String[] columnTitles; public java.io.File downloadedDataFile; static final boolean $assertionsDisabled; public com.americantraction.gui.LineChartController(); LineNumberTable: line 49: 0 line 120: 4 line 215: 15 line 230: 20 line 247: 25 line 254: 36 line 261: 47 line 268: 58 line 275: 69 line 282: 80 line 289: 91 line 296: 102 line 303: 113 line 310: 124 line 317: 135 line 324: 146 line 329: 157 line 334: 164 line 341: 175 line 353: 186 line 361: 197 line 369: 208 line 378: 219 line 386: 230 line 401: 241 line 406: 252 line 411: 263 line 416: 274 line 421: 285 line 426: 296 line 431: 307 line 436: 318 line 441: 329 line 446: 340 line 451: 351 line 456: 362 line 461: 373 line 466: 384 line 471: 395 line 476: 406 line 481: 417 line 486: 428 line 491: 439 line 496: 450 line 501: 461 line 506: 472 line 511: 483 line 516: 494 line 521: 505 LocalVariableTable: Start Length Slot Name Signature 0 517 0 this Lcom/americantraction/gui/LineChartController; public void initialize(); LineNumberTable: line 530: 0 line 531: 4 line 532: 8 line 533: 12 line 534: 16 line 535: 20 line 536: 24 line 539: 28 line 543: 60 line 546: 70 line 547: 85 line 548: 100 line 549: 110 line 550: 126 line 552: 150 line 553: 158 line 554: 169 line 558: 183 line 564: 197 line 572: 206 LocalVariableTable: Start Length Slot Name Signature 0 207 0 this Lcom/americantraction/gui/LineChartController; 158 49 1 inputDialogs Lcom/americantraction/gui/elements/InputDialogs; static {}; LineNumberTable: line 49: 0 line 186: 16 line 193: 26 line 205: 32 }
需求
寻求解决该问题的方案,让Maven打包后的桌面应用日志能正确显示调用文件及行号。
内容的提问来源于stack exchange,提问作者92awdGSX
相关产品推荐
相关产品推荐

