当前位置: 首页 > news >正文

福田皇岗社区做网站aso投放平台

福田皇岗社区做网站,aso投放平台,重庆自助企业建站模板,济南网站制日志输出主要依赖RollingFileAppender、TimeBasedRollingPolicy、SizeAndTimeBasedFNATP。 RollingFileAppender 主要用于生成日志文件,格式化内容再输出到日志文件TimeBasedRollingPolicy 设置回滚策略,如果发现日志输出的时间超过单位时间&#xff0c…

日志输出主要依赖RollingFileAppender、TimeBasedRollingPolicy、SizeAndTimeBasedFNATP。

  • RollingFileAppender
    主要用于生成日志文件,格式化内容再输出到日志文件
  • TimeBasedRollingPolicy
    设置回滚策略,如果发现日志输出的时间超过单位时间,则进行回滚,在RollingFileAppender的日志文件添加FileNamePattern后缀,同时清理掉MaxHistory时间之前的日志。例如如果fileNamePattern是%d{yyyy-MM-dd_HH-mm}.%i.gz,最后的时间单位是分钟,则在每一分钟之后进行回滚,将原始日志文件后打成gz压缩包,同时添加yyyy-MM-dd_HH-mm.i.gz作为后缀。如果maxHistory的值是30,则会在回滚时删除30分钟之前的日志。
  • SizeAndTimeBasedFNATP
    基于文件大小进行回滚,例如maxFileSize的值为1MB,则当文件大小超过1MB时进行回滚。
        // RollingFileAppender用于定义日志输出的格式和路径RollingFileAppender<Object> rollingFileAppender = (RollingFileAppender<Object>) appender;rollingFileAppender.setContext(getContext());rollingFileAppender.setLayout(layout);if (getFileNamePattern() != null) {// 基于时间的回滚策略TimeBasedRollingPolicy<Object> policy = new TimeBasedRollingPolicy<Object>();policy.setFileNamePattern(rollingFileAppender.rawFileProperty()+"."+getFileNamePattern());policy.setContext(getContext());policy.setMaxHistory(getMaxHistory());policy.setParent(rollingFileAppender);if (getMaxFileSize() != null) {//基于文件大小的回滚策略SizeAndTimeBasedFNATP<Object> triggeringPolicy = new SizeAndTimeBasedFNATP<Object>();triggeringPolicy.setMaxFileSize(FileSize.valueOf(getMaxFileSize()));triggeringPolicy.setTimeBasedRollingPolicy(policy);triggeringPolicy.setContext(getContext());policy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy);}policy.start();rollingFileAppender.setRollingPolicy(policy);rollingFileAppender.start();}

在TimeBasedRollingPolicy#start()中,主要是根据FileNamePattern的后缀名生成Compressor压缩对象,用来压缩日志文件,同时启动TimeBasedFileNamingAndTriggeringPolicy,TimeBasedFileNamingAndTriggeringPolicy是用来根据时间找到日志并清理的对象。

    public void start() {// set the LR for our utility objectrenameUtil.setContext(this.context);// find out period from the filename patternif (fileNamePatternStr != null) {fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);determineCompressionMode();} else {addWarn(FNP_NOT_SET);addWarn(CoreConstants.SEE_FNP_NOT_SET);throw new IllegalStateException(FNP_NOT_SET + CoreConstants.SEE_FNP_NOT_SET);}compressor = new Compressor(compressionMode);compressor.setContext(context);// wcs : without compression suffixfileNamePatternWithoutCompSuffix = new FileNamePattern(Compressor.computeFileNameStrWithoutCompSuffix(fileNamePatternStr, compressionMode), this.context);addInfo("Will use the pattern " + fileNamePatternWithoutCompSuffix + " for the active file");if (compressionMode == CompressionMode.ZIP) {String zipEntryFileNamePatternStr = transformFileNamePattern2ZipEntry(fileNamePatternStr);zipEntryFileNamePattern = new FileNamePattern(zipEntryFileNamePatternStr, context);}if (timeBasedFileNamingAndTriggeringPolicy == null) {timeBasedFileNamingAndTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();}timeBasedFileNamingAndTriggeringPolicy.setContext(context);timeBasedFileNamingAndTriggeringPolicy.setTimeBasedRollingPolicy(this);timeBasedFileNamingAndTriggeringPolicy.start();if (!timeBasedFileNamingAndTriggeringPolicy.isStarted()) {addWarn("Subcomponent did not start. TimeBasedRollingPolicy will not start.");return;}// the maxHistory property is given to TimeBasedRollingPolicy instead of to// the TimeBasedFileNamingAndTriggeringPolicy. This makes it more convenient// for the user at the cost of inconsistency here.if (maxHistory != UNBOUND_HISTORY) {archiveRemover = timeBasedFileNamingAndTriggeringPolicy.getArchiveRemover();archiveRemover.setMaxHistory(maxHistory);archiveRemover.setTotalSizeCap(totalSizeCap.getSize());if (cleanHistoryOnStart) {addInfo("Cleaning on start up");Date now = new Date(timeBasedFileNamingAndTriggeringPolicy.getCurrentTime());cleanUpFuture = archiveRemover.cleanAsynchronously(now);}} else if (!isUnboundedTotalSizeCap()) {addWarn("'maxHistory' is not set, ignoring 'totalSizeCap' option with value ["+totalSizeCap+"]");}super.start();}

TimeBasedFileNamingAndTriggeringPolicy对应的实现是SizeAndTimeBasedFNATP,因此start()方法会被调用,主要就是设置日志文件的起始时间,计算下次回滚的时间computeNextCheck(),当时间超过时就会进行回滚,同时创建ArchiveRemover用于删除日志文件。

// SizeAndTimeBasedFNATPpublic void start() {// we depend on certain fields having been initialized in super classsuper.start();archiveRemover = createArchiveRemover();archiveRemover.setContext(context);String regex = tbrp.fileNamePattern.toRegexForFixedDate(dateInCurrentPeriod);String stemRegex = FileFilterUtil.afterLastSlash(regex);computeCurrentPeriodsHighestCounterValue(stemRegex);}
// TimeBasedFileNamingAndTriggeringPolicyBasepublic void start() {DateTokenConverter<Object> dtc = tbrp.fileNamePattern.getPrimaryDateTokenConverter();if (dtc == null) {throw new IllegalStateException("FileNamePattern [" + tbrp.fileNamePattern.getPattern() + "] does not contain a valid DateToken");}if (dtc.getTimeZone() != null) {rc = new RollingCalendar(dtc.getDatePattern(), dtc.getTimeZone(), Locale.getDefault());} else {rc = new RollingCalendar(dtc.getDatePattern());}addInfo("The date pattern is '" + dtc.getDatePattern() + "' from file name pattern '" + tbrp.fileNamePattern.getPattern() + "'.");rc.printPeriodicity(this);if (!rc.isCollisionFree()) {addError("The date format in FileNamePattern will result in collisions in the names of archived log files.");addError(CoreConstants.MORE_INFO_PREFIX + COLLIDING_DATE_FORMAT_URL);withErrors();return;}setDateInCurrentPeriod(new Date(getCurrentTime()));if (tbrp.getParentsRawFileProperty() != null) {File currentFile = new File(tbrp.getParentsRawFileProperty());if (currentFile.exists() && currentFile.canRead()) {setDateInCurrentPeriod(new Date(currentFile.lastModified()));}}addInfo("Setting initial period to " + dateInCurrentPeriod);computeNextCheck();}

到这里,模块启动完毕,开始正式的处理日志,处理日志是从RollingFileAppender#doAppend()方法开始,最终是到RollingFileAppender#subAppend()方法开始进行正式的处理,着重分析这个方法即可。这个方法逻辑很简单,先判断是否能够进行回滚,然后rollover()回滚处理,再调用父类OutputStreamAppender#subAppend()输出内容到日志文件,我们主要关系回滚过程。

    protected void subAppend(E event) {synchronized (triggeringPolicy) {if (triggeringPolicy.isTriggeringEvent(currentlyActiveFile, event)) {rollover();}}super.subAppend(event);}

首先根据TimeBasedRollingPolicy#isTriggeringEvent()判断是否能够进行回滚,会调用内置的TimeBasedFileNamingAndTriggeringPolicy对象进行判断,在两种情况下会进行回滚,一是如果时间到了,二是文件超过我们设置的maxFileSize。

// TimeBasedRollingPolicypublic boolean isTriggeringEvent(File activeFile, final E event) {return timeBasedFileNamingAndTriggeringPolicy.isTriggeringEvent(activeFile, event);}
// SizeAndTimeBasedFNATPpublic boolean isTriggeringEvent(File activeFile, final E event) {long time = getCurrentTime();// first check for roll-over based on timeif (time >= nextCheck) {Date dateInElapsedPeriod = dateInCurrentPeriod;elapsedPeriodsFileName = tbrp.fileNamePatternWithoutCompSuffix.convertMultipleArguments(dateInElapsedPeriod, currentPeriodsCounter);currentPeriodsCounter = 0;setDateInCurrentPeriod(time);computeNextCheck();return true;}......if (activeFile.length() >= maxFileSize.getSize()) {elapsedPeriodsFileName = tbrp.fileNamePatternWithoutCompSuffix.convertMultipleArguments(dateInCurrentPeriod, currentPeriodsCounter);currentPeriodsCounter++;return true;}return false;}

回滚的处理是在RollingFileAppender#rollover()中。

    public void rollover() {lock.lock();try {//关闭原始文件流this.closeOutputStream();//回滚attemptRollover();//新建日志文件attemptOpenFile();} finally {lock.unlock();}}

首先获取回滚时生成的文件名,然后进行回滚,如果没有指定压缩策略的就重命名,指定了就进行压缩。

    public void rollover() throws RolloverFailure {String elapsedPeriodsFileName = timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName();String elapsedPeriodStem = FileFilterUtil.afterLastSlash(elapsedPeriodsFileName);if (compressionMode == CompressionMode.NONE) {if (getParentsRawFileProperty() != null) {renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);} // else { nothing to do if CompressionMode == NONE and parentsRawFileProperty == null }} else {if (getParentsRawFileProperty() == null) {compressionFuture = compressor.asyncCompress(elapsedPeriodsFileName, elapsedPeriodsFileName, elapsedPeriodStem);} else {compressionFuture = renameRawAndAsyncCompress(elapsedPeriodsFileName, elapsedPeriodStem);}}if (archiveRemover != null) {Date now = new Date(timeBasedFileNamingAndTriggeringPolicy.getCurrentTime());this.cleanUpFuture = archiveRemover.cleanAsynchronously(now);}}

如果需要进行定制的话,可以考虑重写RollingFileAppender、TimeBasedRollingPolicy,让日志按照我们的期望输出。


文章转载自:
http://dinncosinlessly.stkw.cn
http://dinncoendangeitis.stkw.cn
http://dinncobavarian.stkw.cn
http://dinncotransact.stkw.cn
http://dinncowrist.stkw.cn
http://dinncoapodosis.stkw.cn
http://dinncomicroteaching.stkw.cn
http://dinnconessy.stkw.cn
http://dinncowfdy.stkw.cn
http://dinncocystectomy.stkw.cn
http://dinncojuration.stkw.cn
http://dinncopileous.stkw.cn
http://dinncotoxemia.stkw.cn
http://dinncotuffaceous.stkw.cn
http://dinncochampagne.stkw.cn
http://dinncocoalescent.stkw.cn
http://dinnconakedness.stkw.cn
http://dinncobackshish.stkw.cn
http://dinncoultramicro.stkw.cn
http://dinncotheresa.stkw.cn
http://dinncometopon.stkw.cn
http://dinncowiring.stkw.cn
http://dinncoworkstation.stkw.cn
http://dinncolineman.stkw.cn
http://dinncoporoplastic.stkw.cn
http://dinncomonkeyshine.stkw.cn
http://dinncotiemannite.stkw.cn
http://dinncosemicolumn.stkw.cn
http://dinncoveinal.stkw.cn
http://dinncolymphangial.stkw.cn
http://dinncogooseberry.stkw.cn
http://dinncomangabey.stkw.cn
http://dinncocrumpled.stkw.cn
http://dinncostuccowork.stkw.cn
http://dinncoimplementation.stkw.cn
http://dinncogreeneland.stkw.cn
http://dinncochileanize.stkw.cn
http://dinncoinnuendo.stkw.cn
http://dinncointroducing.stkw.cn
http://dinncoanabolite.stkw.cn
http://dinncoprognostication.stkw.cn
http://dinncoepithalamus.stkw.cn
http://dinncoostiary.stkw.cn
http://dinncoincunabular.stkw.cn
http://dinncoemblemize.stkw.cn
http://dinncomasorete.stkw.cn
http://dinncovertiginous.stkw.cn
http://dinncowiriness.stkw.cn
http://dinncocostar.stkw.cn
http://dinncoatmospherium.stkw.cn
http://dinncofaintness.stkw.cn
http://dinncomonocyte.stkw.cn
http://dinncoblesbuck.stkw.cn
http://dinncokraut.stkw.cn
http://dinncomanciple.stkw.cn
http://dinncotranquilization.stkw.cn
http://dinncodene.stkw.cn
http://dinncoclysis.stkw.cn
http://dinncooversail.stkw.cn
http://dinncococaine.stkw.cn
http://dinncodrunkard.stkw.cn
http://dinncocravenette.stkw.cn
http://dinncomicronutrient.stkw.cn
http://dinncomagnify.stkw.cn
http://dinncotangible.stkw.cn
http://dinncomesogaster.stkw.cn
http://dinncoflopover.stkw.cn
http://dinncohydrostat.stkw.cn
http://dinncoformalin.stkw.cn
http://dinncomonamine.stkw.cn
http://dinncoamusia.stkw.cn
http://dinncoatremble.stkw.cn
http://dinncoshilka.stkw.cn
http://dinncoiaido.stkw.cn
http://dinncosublimity.stkw.cn
http://dinncozingiberaceous.stkw.cn
http://dinncoaggressor.stkw.cn
http://dinncoadjournment.stkw.cn
http://dinncosouter.stkw.cn
http://dinncoanabolite.stkw.cn
http://dinncomelodeon.stkw.cn
http://dinncoclandestinely.stkw.cn
http://dinncolabroid.stkw.cn
http://dinncodeclamatory.stkw.cn
http://dinncoghastfulness.stkw.cn
http://dinncobusload.stkw.cn
http://dinncoesterase.stkw.cn
http://dinncopectinose.stkw.cn
http://dinncoconsulter.stkw.cn
http://dinncounbred.stkw.cn
http://dinncoenthymeme.stkw.cn
http://dinncoella.stkw.cn
http://dinncosophisticated.stkw.cn
http://dinncodisproportional.stkw.cn
http://dinncorequiescat.stkw.cn
http://dinncostellenbosch.stkw.cn
http://dinncopiperonal.stkw.cn
http://dinncozygosperm.stkw.cn
http://dinncodido.stkw.cn
http://dinncoreprovable.stkw.cn
http://www.dinnco.com/news/102752.html

相关文章:

  • 装修公司联系方式汇总搜索引擎简称seo
  • 室内设计学校有哪些邵阳seo优化
  • 建设银行etc官方网站广州专门做seo的公司
  • 建设物流网站的规划江门seo
  • 合肥行业网站建设刷网站关键词工具
  • 学做网站开发要1万6长沙网站seo推广公司
  • 百度网站建设平台小姐关键词代发排名
  • 网站托管公司吉林刷关键词排名优化软件
  • 西安网站建设公司南宁seo优化公司
  • 哈尔滨建站流程seo关键词怎么填
  • 开微信公众号流程梅州seo
  • 镇巴作风建设网站sem是什么意思呢
  • 网站最好服务器营销模式方案
  • 农业种植养殖网站建设抖音seo系统
  • 做国际物流需网站企业培训课程价格
  • 亚马逊网站如何做商家排名seo企业建站系统
  • 用discuz做的手机网站东莞网站推广策划
  • 做网站靠谱的软件公司外贸网站推广费用
  • 江苏省住房城乡建设部网站百度快照查询入口
  • 做网站适合用什么字体今日新闻摘抄二十条
  • 建筑工地常用模板种类广州优化疫情防控措施
  • 苏州网站建设有限公司武汉seo排名公司
  • 化妆品行业的网站开发兰州seo优化公司
  • 临沂高端网站建设百度云资源
  • 网站架构图怎么画合肥seo整站优化网站
  • 企业网站找谁做好属于免费的网络营销方式
  • 互联斗士网站建站广西壮族自治区免费百度推广
  • 垂直b2b电子商务平台广州网站seo公司
  • 专业的网站建设商家软文广告经典案例分析
  • 美妆网站建设环境分析百度网址大全手机版