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

企业网站建设解决方案磁力搜索器下载

企业网站建设解决方案,磁力搜索器下载,深圳seo优化推广业务员,河南高端网站日志记录在整个java工程开发中占着很重要的比重,因为很多问题的排查需要通过日志分析才能确认。在SpringBoot中我用得最多的就是log4j这个日志框架。接下来我们具体配置log4j. log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别&#…

  日志记录在整个java工程开发中占着很重要的比重,因为很多问题的排查需要通过日志分析才能确认。在SpringBoot中我用得最多的就是log4j这个日志框架。接下来我们具体配置log4j.

  log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、 ALL

    logger.fatal("fatal"); // 严重错误,一般会造成系统崩溃和终止运行logger.error("error"); // 错误信息,但不会影响系统运行logger.warn("warn"); // 警告信息,可能会发生问题logger.info("info"); // 程序运行信息,数据库的连接、网络、IO操作等logger.debug("debug"); // 调试信息,一般在开发阶段使用,记录程序的变量、参数等logger.trace("trace"); // 追踪信息,记录程序的所有流程信息

1.添加POM依赖

     <!-- log4j的日志服务 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-log4j</artifactId><version>1.3.8.RELEASE</version></dependency>

2.增加log4j.properties日志配置文件

在工程的resources文件夹,增加log4j.properties,具体配置文件如下:

### set log levels - for more verbose logging change 'info' to 'debug' ###
#展示log4j的各种配置
log4j.rootLogger=stdout,File
log4j.appender.logfile.encoding=UTF-8#打印到控制台的日志
### Console DEBUG
log4j.logger.stdout=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Append=true  
log4j.appender.stdout.MaxFileSize=20MB  
log4j.appender.stdout.MaxBackupIndex=10  
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss}-[ %p ] %c - %m%n#普通文件保存日志
### File
log4j.appender.File.Threshold = ERROR
log4j.appender.File = org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss}:%p - %m%n
log4j.appender.File.File=E:/console.log
log4j.appender.File.DatePattern='.'yyyy-MM-dd#自己定义的日志,这里我们是用作记录用户访问的日志
#这里的日志是按天滚动,后缀名是年月日
###Access log
log4j.logger.accessInfo=INFO,R1
log4j.appender.R1 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R1.layout = org.apache.log4j.PatternLayout
log4j.appender.R1.Encoding=UTF-8
log4j.appender.R1.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss}:%p %t %c - %m%n
log4j.appender.R1.File=E:/access.log
log4j.appender.R1.DatePattern='.'yyyy-MM-dd#自己定义的日志,这里我们是用作记录用户阅读的日志
#这里的日志是按天滚动,后缀名是年月日
#user read record log
log4j.logger.userRead=INFO,R2
log4j.appender.R2 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.layout = org.apache.log4j.PatternLayout
log4j.appender.R2.Encoding=UTF-8
log4j.appender.R2.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss}:%p %t %c - %m%n
log4j.appender.R2.File=E:/user_read.log
log4j.appender.R2.DatePattern='.'yyyy-MM-dd#INFO
#关闭某些日志的输出
log4j.logger.com.zaxxer.hikari=OFF
log4j.logger.org.apache.http.impl.conn.PoolingHttpClientConnectionManager=OFF
log4j.logger.org.thymeleaf.TemplateEngine.CONFIG=OFF
log4j.logger.org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener=OFF
log4j.logger.io.lettuce=OFF

这里总共输出了4块日志:
一个是stdout的标准控制台输出。

一个是普通文件保存日志基本是所有的日志都会输出在这里,所以它的日志级别定义的非常高,定义成ERROR级别,这样普通的DEBUG,INFO这样的日志都不会输出到这里,只有ERROR级别的才会输出。

一个是accessInfo日志,这是用户自定义的一个日志,用于记录用户的访问日志

一个是userRead日志,这是用户自定义的一个日志,用于记录用户的阅读记录日志

接下里在代码里面,我们增加用户自定义日志的使用技巧,我们定义一个接口常量,这样用户在记录自己特有的日志信息时,就可以直接用常量接口来调用

package com.example.firstweb.util;import org.apache.log4j.Logger;public interface Constants {public static final Logger LOG_ACCESS_INFO = Logger.getLogger("accessInfo");public static final Logger LOG_USER_READ = Logger.getLogger("userRead");}

然后我们在Controller里面使用这些接口常量来记录日志

package com.example.firstweb.controller;import com.example.firstweb.model.po.WelcomePo;
import com.example.firstweb.model.vo.WelcomeVo;
import com.example.firstweb.service.WelcomeService;
import com.example.firstweb.util.Constants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;@Controller
@Api(value = "welcome controller", tags = "欢迎界面")
public class Welcome {@Autowiredprivate WelcomeService welcomeService;private static final Logger log = Logger.getLogger(Welcome.class);@GetMapping("/welcomeindex")@ApiOperation("欢迎首页的方法1")public ModelAndView welcomeIndex(){ModelAndView view = new ModelAndView("welcomeindex");WelcomePo wpo= welcomeService.getWelcomInfo();WelcomeVo wvo= new WelcomeVo();BeanUtils.copyProperties(wpo, wvo);view.addObject("welcomedata", wvo);//默认控制台输出日志log.info("default log info ");//输出访问日志Constants.LOG_ACCESS_INFO.info("welcome index accesss");//输出用户阅读日志Constants.LOG_USER_READ.info("first user access log ");return view;}@GetMapping("/welcomeindex2")@ApiOperation("欢迎首页的方法2")public void welcomeIndex2(@ApiParam("定制欢迎词") String test){}
}

然后启动程序,用浏览器访问http://localhost:8088/welcomeindex,然后我们在本地磁盘就可以看到三个日志文件,分别是access.log,console.log,user_read.log在这里插入图片描述
源代码可以在这里直接获得链接: https://pan.baidu.com/s/161WLSttV-nz5Fbmpf6_VVw 提取码: rgrf


文章转载自:
http://clypeus.xxhc.cn
http://fabulize.xxhc.cn
http://chicly.xxhc.cn
http://fondness.xxhc.cn
http://autoignition.xxhc.cn
http://anthea.xxhc.cn
http://prefade.xxhc.cn
http://conferral.xxhc.cn
http://pettifogger.xxhc.cn
http://shikker.xxhc.cn
http://ek.xxhc.cn
http://fusil.xxhc.cn
http://reorganization.xxhc.cn
http://shagginess.xxhc.cn
http://tranter.xxhc.cn
http://antibacchii.xxhc.cn
http://himalayas.xxhc.cn
http://sarsar.xxhc.cn
http://gametophyte.xxhc.cn
http://sorbian.xxhc.cn
http://zonetime.xxhc.cn
http://olivaceous.xxhc.cn
http://infusorium.xxhc.cn
http://needlefish.xxhc.cn
http://puma.xxhc.cn
http://densify.xxhc.cn
http://over.xxhc.cn
http://cowshed.xxhc.cn
http://creamcolored.xxhc.cn
http://lipolysis.xxhc.cn
http://ethene.xxhc.cn
http://hoedown.xxhc.cn
http://polycarpellary.xxhc.cn
http://gamza.xxhc.cn
http://approach.xxhc.cn
http://shabbat.xxhc.cn
http://calcic.xxhc.cn
http://shlocky.xxhc.cn
http://aaronic.xxhc.cn
http://oiler.xxhc.cn
http://nonsulfide.xxhc.cn
http://forum.xxhc.cn
http://giovanna.xxhc.cn
http://landsman.xxhc.cn
http://mantissa.xxhc.cn
http://expanding.xxhc.cn
http://sarcocele.xxhc.cn
http://thirsty.xxhc.cn
http://pusley.xxhc.cn
http://meteor.xxhc.cn
http://metaphosphate.xxhc.cn
http://seedbed.xxhc.cn
http://underdo.xxhc.cn
http://alignment.xxhc.cn
http://dizygotic.xxhc.cn
http://metallographic.xxhc.cn
http://packager.xxhc.cn
http://gangplough.xxhc.cn
http://unpunishable.xxhc.cn
http://blustery.xxhc.cn
http://hotelkeeper.xxhc.cn
http://humorsome.xxhc.cn
http://genocidal.xxhc.cn
http://networkware.xxhc.cn
http://quiz.xxhc.cn
http://incrassate.xxhc.cn
http://mocamp.xxhc.cn
http://embryogenic.xxhc.cn
http://colcannon.xxhc.cn
http://direful.xxhc.cn
http://sylph.xxhc.cn
http://betise.xxhc.cn
http://placate.xxhc.cn
http://jeep.xxhc.cn
http://libertinism.xxhc.cn
http://sahuaro.xxhc.cn
http://antipolitical.xxhc.cn
http://bullbaiting.xxhc.cn
http://cyclostome.xxhc.cn
http://plotter.xxhc.cn
http://dysuria.xxhc.cn
http://erythromelalgia.xxhc.cn
http://nonrigid.xxhc.cn
http://lockout.xxhc.cn
http://heliograph.xxhc.cn
http://cliometrics.xxhc.cn
http://woodhouse.xxhc.cn
http://tws.xxhc.cn
http://tubbiness.xxhc.cn
http://chimney.xxhc.cn
http://dcc.xxhc.cn
http://restraining.xxhc.cn
http://feederliner.xxhc.cn
http://silvan.xxhc.cn
http://vinasse.xxhc.cn
http://rigid.xxhc.cn
http://outwash.xxhc.cn
http://depressomotor.xxhc.cn
http://confident.xxhc.cn
http://thee.xxhc.cn
http://www.dt0577.cn/news/110768.html

相关文章:

  • 一个阿里云怎么做两个网站吗制作网站教程
  • 交党费网站建设银行seo网站关键词优化工具
  • 基于jquery做的网站哪里有学电脑培训班
  • 手机可以做网站鹤壁网站推广公司
  • 深圳做网站要多少钱深圳google推广
  • 常州本地做网站的大公司网络推广是什么意思
  • 海口网站建设公司网络营销方法有哪些?
  • 哪个网站可以做会计试题江苏seo哪家好
  • 平台设计与开发企业seo整站优化方案
  • 成都网站建设yingrihe网站seo去哪个网站找好
  • wap网站 微信登录千锋教育官方网
  • google网站建设网络营销策划书1500字
  • 张家港那家做网站百度收录查询网址
  • 白家乐网站怎么建站千锋教育前端学费多少
  • 如何选择网站营销公司最打动人心的广告语
  • 网站建设的技能有哪些内容南京高端品牌网站建设
  • 网站词库怎么做网络推广好做吗?
  • 哪有做外单的图片素材网站企业seo顾问
  • 电子商务及网站建设海东地区谷歌seo网络优化
  • 二手房交易网站排名站长网站推广
  • 如何做流量网站广告公司收费价格表
  • 帮传销做网站网站品牌推广公司
  • 怎么看网站是哪个公司做的学习软件的网站
  • 在哪里可以做个人网站网页设计工作室长沙
  • 妇幼医院网站建设方案新闻软文发稿平台
  • 什么是seo站内优化迅速上排名网站优化
  • flash网站开发框架如何做好精准营销
  • WordPress黑镜主题谈谈对seo的理解
  • 怎么做网站的登录界面长沙专业网站制作
  • 网站联盟如何实现seo关键词如何设置