温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springboot中怎么管理日志

发布时间:2021-06-18 16:16:40 来源:亿速云 阅读:157 作者:Leah 栏目:大数据

springboot中怎么管理日志,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

springBoot添加日志管理

一。

近期自己的项目想要一个记录日志的功能,而springboot本身就内置了日志功能,然而想要输入想要的日志,并且输出到磁盘,然后按天归档,或者日志的切分什么的,自带的日志仅仅具有简单的功能,百度了一番,总结如下,适合大多数的应用场景

二。

springboot的pom文件都会引一个parent

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

点进去这个parent,会有一个这个dependency

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath>../../spring-boot-dependencies</relativePath>
    </parent>

再点进去就是2.0版本,所谓的它给你集成的各种包依赖,而且规定了版本号,其中有一个包如下

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.0.0.RELEASE</version>
    </dependency>

再点进去

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
      <version>2.0.0.RELEASE</version>
      <scope>compile</scope>
    </dependency>

再点,啊哈,出来了,这些都是原有的日志包,所以,不必再引依赖了,直接用就ok了,用法如下:

springboot中怎么管理日志

<dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-to-slf4j</artifactId>
      <version>2.10.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jul-to-slf4j</artifactId>
      <version>1.7.25</version>
      <scope>compile</scope>
    </dependency>
rsion="1.0">其中说一下,彩色日志这个东东,得下载插件才可以哦,怎么下?我不知道哈哈然后在yml或者properties中配置logging.config=classpath:log/logback-spring.xml
logging.path=D:/nmyslog/nmys 日志的使用方式,就跟普通使用一样,只不过,此配置配置的是不仅在控制台输出而且在磁盘上也会保留,并且info/debug/error/warn的日志都区分开了,并且按照每天做了归档

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI