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 ?

3
  • Possible duplicate of Logback to log different messages to two files Commented Jul 15, 2019 at 8: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. Commented Jul 15, 2019 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 . Commented Jul 19, 2019 at 16:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.