How can I paint the data that the logger brings to me in a txt file?

-1

Hello, I am creating a class where I am extracting data from a database but I am painting the data in a logger. would like to help me so that instead of painting it in the logger, a txt is created and painted in the file. What I have so far is the following.

package com.bbva.mjia.batch.writer;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemWriter;

import com.bbva.mjia.batch.writer.Writer;

public class Writer implements ItemWriter<Map<String, Object>>{
    private static final Logger LOGGER = LoggerFactory.getLogger(Writer.class);

    @Override
    public void write(List<? extends Map<String, Object>> chunk) throws Exception {
        for(Map<String,Object>mapa:chunk){
            System.out.println(mapa.toString());
            LOGGER.info(mapa.toString());



        }

    }

}
    
asked by francisco may 07.06.2018 в 01:11
source

1 answer

0

If you do not have any logging library in your classpath, SLFJ, as its documentation says, will not do anything: SINCE 1.6.0 If no binding is found on the class path, then SLF4J will default to a no-operation implementation. enter the description of the link here .

If you use Log4J, you must:

  • Download the JAR from Log4j and include it in the classpath of your project
  • In a folder that is part of the source code of your project, create a file called log4j2.properties with this example configuration:

    status = error name = PropertiesConfig

    property.filename = \ output.log

    filters = threshold

    filter.threshold.type = ThresholdFilter filter.threshold.level = debug

    appenders = rolling

    appender.rolling.type = RollingFile appender.rolling.name = RollingFile appender.rolling.fileName = $ {filename} appender.rolling.filePattern = debug-backup-% d {MM-dd-yy-HH-mm-ss} -% i.log.gz appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern =% d {yyyy-MM-dd HH: mm: ss}% -5p% c {1}:% L -% m% n appender.rolling.policies.type = Policies appender.rolling.policies.time.type = TimeBasedTriggeringPolicy appender.rolling.policies.time.interval = 1 appender.rolling.policies.time.modulate = true appender.rolling.policies.size.type = SizeBasedTriggeringPolicy appender.rolling.policies.size.size = 10MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 20

    loggers = rolling

    logger.rolling.name = com.bbva.mjia.batch.writer logger.rolling.level = debug logger.rolling.additivity = false logger.rolling.appenderRef.rolling.ref = RollingFile

This should be enough to see that the logs you generate are written to the file you specified in those properties.

    
answered by 07.06.2018 в 20:47