Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Apache Log4j Security Vulnerabilities - 2.17.0 jar not load Lookup values into log4j2.xml

As per Apache Log4j Security Vulnerabilities guideline i have updated 2.17.0 jar in my application.

Post upgrade Log files not getting generated.

Spring version : 5.3.13
Log4j version : 2.17.0
java : 1.8

Refer the given below log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="1">
    <Properties>
        
        <Property name="log-path">${appconfig:log_path}</Property>
        <Property name="log-name">${appconfig:filename}</Property>
        <Property name="archive-days">${appconfig:archive_days}</Property>
        <Property name="file-level">${appconfig:file_level}</Property>
        <Property name="console-level">${appconfig:console_level}</Property>
         
        
    </Properties>
    <Appenders>

        <Routing name="route-log">
            <Routes pattern="${ctx:routingLogFile}">
                
                <Route>
                    <RollingFile name="default-log" fileName="${log-path}/${log-name}.log"
                                 filePattern="${log-path}/${date:yyyy-MM}/${log-name}.%d{MM-dd-yyyy}-%i.log.gz" append="true">
                        <PatternLayout
                                pattern="%d{MM/dd/yyyy HH:mm:ss.SSS z} %X{machine-name} %X{app-name} [%t] %-5level %logger{36}:%-3L - %msg%n" />
                        <Policies>
                            <TimeBasedTriggeringPolicy />
                            <SizeBasedTriggeringPolicy size="150 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="1000">
                            <Delete basePath="${log-path}/" maxDepth="2">
                                <IfFileName glob="/${log-name}*.log.gz" />
                                <IfLastModified age="${archive-days}" />
                            </Delete>
                        </DefaultRolloverStrategy>
                    </RollingFile >
                </Route>
        
            </Routes>
                
        </Routing>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ISO8601} %-5level %30.30logger{1.}:%-3L - %m%n%throwable" />
        </Console>
    </Appenders>
    
    <Loggers>
        <Logger name="org.springframework" level="ERROR"/>
         <Logger name="org.apache" level="ERROR"/>
        <Root level="${file-level}" additivity="false">
            <AppenderRef ref="route-log" />
            <AppenderRef ref="STDOUT" />
        </Root>
    </Loggers>
    
</Configuration>

I am using given below lookup, in order to get the log file name , log file path ,log level,archive days from table.

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.lookup.AbstractLookup;
import org.apache.logging.log4j.core.lookup.StrLookup;
import org.appconfig.properties.ApplicationProperties;
import org.springframework.util.StringUtils;

@Plugin(name = "appconfig", category = StrLookup.CATEGORY)
public class AppLog4JConfigDatabaseLookup extends AbstractLookup {

    public String lookup(final LogEvent event, final String key) {
        
        
        if (key.equalsIgnoreCase("filename")) {
            return ApplicationProperties.getLogFilename();
        }
        if (key.equalsIgnoreCase("log_path")) {
            return ApplicationProperties.getLogPath();
        }
        if (key.equalsIgnoreCase("file_level")) {
            return ApplicationProperties.getFileLogLevel();
        }
        if (key.equalsIgnoreCase("console_level")) {
            return ApplicationProperties.getConsoleLogLevel();
        }
        if (key.equalsIgnoreCase("app_name")) {
            return ApplicationProperties.getAppName();
        }
        if (key.equalsIgnoreCase("archive_days")) {
            return ApplicationProperties.getLogArchiveDays();
        }
        
        return key;
    }
}

Refer the given below service class.

public class LoaderJob extends SchedulerAdapterJob {
    @Autowired
    private FileLoaderJob fileLoaderJob;
    
    private static final Logger LOGGER = LogManager.getLogger(LoaderJob.class);
    @Override
    public void executeJob(JobExecutionContext jobExecutionContext) {
        ThreadContext.put("routingLogFile","LOADER_LOGS");
        try {
            fileLoaderJob.execute();        
            
        }
        catch (Exception e) {
            LOGGER.error("Exception in  "+getJobName()+" : "+ e.getMessage());
            throw e;
        }
        finally {
              ThreadContext.remove("routingLogFile");
        }       
        
    }

}

its was working fine with 2.16.0 , not working in 2.17.0. Any solution would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As per Apache guideline, you should add two $ in routes pattern. But in your log4j2.xml contains only one

Refer the below link: https://logging.apache.org/log4j/log4j-2.2/faq.html

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda