<?xml version="1.0" encoding="UTF-8"?> <Configuration status="warn"> <Appenders> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH}.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1"/> <SizeBasedTriggeringPolicy size="250MB"/> </Policies> </RollingFile> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<SizeBasedTriggeringPolicy size="250MB"/>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="warn" name="MyApp" packages=""> <Appenders> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH}-%i.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="250 MB"/> </Policies> </RollingFile> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="250 MB"/> </Policies>
<DefaultRolloverStrategy max="7"/>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd}.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <SizeBasedTriggeringPolicy size="10KB"/> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%i.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <SizeBasedTriggeringPolicy size="10KB"/> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH-mm}-%i.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="10KB"/> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="warn" name="MyApp" packages=""> <Properties> <Property name="baseDir">logs</Property> </Properties> <Appenders> <RollingFile name="RollingFile" fileName="${baseDir}/app.log" filePattern="${baseDir}/app-%d{yyyy-MM-dd}.log.gz"> <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" /> <CronTriggeringPolicy schedule="0 0 0 * * ?"/> <DefaultRolloverStrategy> <Delete basePath="${baseDir}" maxDepth="2"> <IfFileName glob="*/app-*.log.gz" /> <IfLastModified age="60d" /> </Delete> </DefaultRolloverStrategy> </RollingFile> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
public class HelloWorld { public static void main(String[] args) { Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME); try{ //通过打印i,日志文件中数字越小代表越老 for(int i = 0; i < 50000; i ) { logger.info("{}", i); logger.info("logger.info\n"); Thread.sleep(100);//为了防止50000条很快跑完,sleep一段时间 } } catch (InterruptedException e) {} } }
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <!--<RollingFile name="RollingFile" fileName="logs/app.log"--> <!--filePattern="logs/app-%d{yyyy-MM-dd HH}-%i.log">--> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH-mm-ss}.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <!--当经过了interval时间后,将根据filePattern对文件进行重命名,并生成新的文件用于日志写入--> <TimeBasedTriggeringPolicy interval="5"/> <!--当日志文件大小大于size时,将根据filepattern对文件进行重命名,并生成新的文件用于日志写入--> <!--<SizeBasedTriggeringPolicy size="30KB"/>--> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <!--<RollingFile name="RollingFile" fileName="logs/app.log"--> <!--filePattern="logs/app-%d{yyyy-MM-dd HH}-%i.log">--> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH-mm-ss}.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <!--当经过了interval时间后,将根据filePattern对文件进行重命名,并生成新的文件用于日志写入--> <!--<TimeBasedTriggeringPolicy interval="5"/>--> <!--当日志文件大小大于size时,将根据filepattern对文件进行重命名,并生成新的文件用于日志写入--> <SizeBasedTriggeringPolicy size="5KB"/> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" name="MyApp" packages=""> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd HH-mm}-%i.log"> <!--<RollingFile name="RollingFile" fileName="logs/app.log"--> <!--filePattern="logs/app-%d{yyyy-MM-dd HH-mm-ss}.log">--> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <!--当经过了interval时间后,将根据filePattern对文件进行重命名,并生成新的文件用于日志写入--> <!--<TimeBasedTriggeringPolicy interval="5"/>--> <!--当日志文件大小大于size时,将根据filepattern对文件进行重命名,并生成新的文件用于日志写入--> <SizeBasedTriggeringPolicy size="5KB"/> </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
END 十期推荐 【271期】面试官:Spring MVC的处理流程是怎样的? 【272期】数据结构:哈希表原理以及面试中的常见考点 【273期】告诉面试官,我能优化groupBy,而且知道得很深! 【274期】面试官:怎么保证缓存和数据库一致性 【275期】面试官:你对MySQL中的索引了解多少? 【276期】面试官:你分析过@Annotation注解的实现原理吗? 【277期】面试官:说几种常用的分布式 ID 解决方案 【278期】面试官:都说 select * 效率低下,你知道什么原因吗? 【279期】面试官:Java遍历Map集合有哪几种方式?各自效率怎么样? 【280期】k8s面试问什么? ? ~