how to write only program specific logs to file in spring batch with spring boot

眉间皱痕 提交于 2019-12-24 21:36:16

问题


I have developed spring batch multifile processor. Now requirement is to write all program specific logs like for example:

    logger.info(" this is reader reading employee record:" employee.toString);
    logger.info(" this is processor processing employee record:" employee.toString);

to the file. Tried to solve by using logback.xml.

<appender name="file1" class="ch.qos.logback.core.FileAppender">
    <file>${LOG_PATH}/log.log</file>
     <encoder 
      class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <Pattern>%msg%</Pattern>
    </encoder>
</appender>

then started disabling all other logs of spring, hibernate etc...

<logger name="org.springframework" level="OFF">
   <appender-ref ref="file1" />
</logger>

did the same for org.hibernate. but looking like i have to disable lot like tomcat and org.apache etc...

any suggestion to send only program logs which were written in methods to the log file.

As this is spring batch any way it can be simplified ?


回答1:


As i did not get any easy way, this is what i did.

Added all logs to list. returned same in processor. in writer written those logs to file.



来源:https://stackoverflow.com/questions/57015378/how-to-write-only-program-specific-logs-to-file-in-spring-batch-with-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!