0

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 ?

  • Possible duplicate of [Logback to log different messages to two files](https://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files) – Mahmoud Ben Hassine Jul 15 '19 at 08:00
  • thank you.i have referred the above post while implementing solution. loggers are at info level in batch processor class. when directing processor class logs to file, at the same time other logs which are at info level like "started service","application started" and some info level logs related to Tomcat written. so if anything to extract only logs which were written by developer is so helpful. if not, have to disable other logs forcefully so chance of writing some unwanted logs. may be writing logs to list then in writer step write to file. performance of job is key while doing so. – sriharsha ch Jul 15 '19 at 17:35
  • As i did not get any easy way to use logback for generating program specific logs, i have moved them to list then in writer i am creating file . – sriharsha ch Jul 19 '19 at 16:45

1 Answers1

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.