How to disable log4j logging from Java code

前端 未结 8 1659
难免孤独
难免孤独 2021-02-07 13:58

I use a legacy library that writes logs using log4j. My default log4j.properties file directs the log to the console, but in some specific functions of my main program, I would

8条回答
  •  春和景丽
    2021-02-07 14:46

    Add the following to your log file

    log4j.logger.com.class.with.package.BasicImplementation = off, logfiledata
    
    log4j.appender.logfiledata = ac.biu.nlp.nlp.log.BackupOlderFileAppender
    log4j.appender.logfiledata.append=false
    log4j.appender.logfiledata.layout = org.apache.log4j.PatternLayout
    log4j.appender.logfiledata.layout.ConversionPattern = %-5p %d{HH:mm:ss} [%t]: %m%n
    log4j.appender.logfiledata.File = logfiledata.log
    

    If the above will not stop if from logging, it will at least log all the data from BasicImplementation class to a separate file.

提交回复
热议问题