至于存到数据游纳库,那就得再打开log日志找到所需要的信息做 *** 作了。
import java.util.logging.*
import java.io.* public class MemoryHandlerTest { FileHandler fhandler Logger logger MemoryHandler mhandler MemoryHandlerTest() { try { fhandler = new FileHandler("my.log") int numRec = 5 mhandler = new MemoryHandler(fhandler, numRec, Level.OFF) logger = Logger.getLogger("com.mycompany") logger.addHandler(mhandler) } catch (IOException e) {
} } public static void main(String args[]) { MemoryHandlerTest mt = new MemoryHandlerTest() int trigger = (int) (Math.random() * 100) for (int i = 1 i < 100 i++) { mt.logger.log(Level.INFO, "日志记录" + i) if (i == 旦顷trigger) { mt.mhandler.push() break } } } }
#RollingFilelog4j.category.com.jshx.jshx=DEBUG,file
log4j.additivity.com.jshx.jshx=false
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/行虚唤logs/program/誉明jshx.log
log4j.appender.file.DatePattern='档凯.'yyyy-MM-dd
#log4j.appender.RollingFile.MaxFileSize=10MB
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %-40.40c %X{traceId}-%m%n
log4j.appender.file.Threshold=DEBUG
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)