不是为基于maven的java项目使用log4j创建的日志文件

qfe3c7zg  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(252)

试着寻找各种线索,但不知怎么还是搞不清楚。
我有一个基于maven的java应用程序,它生成一个jar文件。下面是我的pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>jdbc</groupId>
  6. <artifactId>format.jdbc.queries</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <build>
  9. <plugins>
  10. <plugin>
  11. <groupId>org.apache.maven.plugins</groupId>
  12. <artifactId>maven-assembly-plugin</artifactId>
  13. <configuration>
  14. <archive>
  15. <manifest>
  16. <mainClass>format.jdbc.queries.FormatterEntryPoint</mainClass>
  17. </manifest>
  18. <manifestEntries>
  19. <Class-Path>.</Class-Path>
  20. </manifestEntries>
  21. </archive>
  22. <descriptorRefs>
  23. <descriptorRef>jar-with-dependencies</descriptorRef>
  24. </descriptorRefs>
  25. </configuration>
  26. <executions>
  27. <execution>
  28. <id>make-assembly</id>
  29. <phase>package</phase>
  30. <goals>
  31. <goal>single</goal>
  32. </goals>
  33. </execution>
  34. <execution>
  35. <phase>install</phase>
  36. <goals>
  37. <goal>single</goal>
  38. </goals>
  39. </execution>
  40. </executions>
  41. </plugin>
  42. <plugin>
  43. <groupId>org.apache.maven.plugins</groupId>
  44. <artifactId>maven-release-plugin</artifactId>
  45. <version>2.5.1</version>
  46. <configuration>
  47. <goals>install</goals>
  48. <preparationGoals>install</preparationGoals>
  49. </configuration>
  50. </plugin>
  51. <plugin>
  52. <groupId>org.apache.maven.plugins</groupId>
  53. <artifactId>maven-compiler-plugin</artifactId>
  54. <version>3.5.1</version>
  55. <configuration>
  56. <source>1.8</source>
  57. <target>1.8</target>
  58. </configuration>
  59. </plugin>
  60. </plugins>
  61. <resources>
  62. <resource>
  63. <directory>src/main/resources</directory>
  64. <targetPath>${project.build.directory}</targetPath>
  65. <includes>
  66. <include>log4j.properties</include>
  67. </includes>
  68. </resource>
  69. </resources>
  70. </build>
  71. <dependencies>
  72. <dependency>
  73. <groupId>log4j</groupId>
  74. <artifactId>log4j</artifactId>
  75. <version>1.2.15</version>
  76. </dependency>
  77. </dependencies>
  78. </project>

我的log4j.properties放在src/main/resources下,内容如下:

  1. # Root logger option
  2. log4j.rootLogger=DEBUG, file
  3. # Redirect log messages to a log file, support file rolling.
  4. log4j.appender.file=org.apache.log4j.RollingFileAppender
  5. log4j.appender.file.File=/tmp/jdbc-formatter.log
  6. log4j.appender.file.MaxFileSize=5MB
  7. log4j.appender.file.MaxBackupIndex=10
  8. log4j.appender.file.layout=org.apache.log4j.PatternLayout
  9. log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

以下是我的主要课堂内容:

  1. private static final Logger log = LogManager.getLogger(FormatterEntryPoint.class);
  2. public static void main(String[] args) {
  3. BasicConfigurator.configure();
  4. CommandLineArgumentsHandler cliHandler = new CommandLineArgumentsHandler();
  5. try {
  6. cliHandler.parse(args);
  7. } catch (IllegalArgumentException e) {
  8. log.debug(e.getMessage(),e);
  9. System.err.println("Usage: java -jar <program_name> -input=<path_to_jdbc_log> -output=<output_file>");
  10. }
  11. }

当我从命令行运行jar时,虽然我在控制台中看到日志消息,但是日志文件/tmp/jdbc-formatter.log没有被创建。有什么意见吗?
谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题