zoukankan      html  css  js  c++  java
  • 在springboot访问日志

    1.废话不多说,直接上工程结构。

    2.启动类随便加一个方法。

    @GetMapping("/hello")
        public String hello() {
            return "hello";
        }

    3.主要是yml文件的配置参数。

    server:
      tomcat:
        basedir: my-tomcat
        accesslog:
          pattern: 'ip: %A, response code: %s, time: %t'
          enabled: true
          directory: crazyit-logs
          buffered: false

    注:basedir指的是我们定义的根目录,而directory指的是生成的log存放目录,我们可根据需要修改目录路径。

    4.pom文件。

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.crazyit.boot.c3</groupId>
        <artifactId>log-test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.1.RELEASE</version>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        
    </project>

    5.访问localhost:8080/hello后,刷新工程后,可在指定目录看到生成的log文件。

  • 相关阅读:
    spring整合Quartz
    Quartz基本使用
    hibernate框架基础描述
    POI技术实现对excel的导出
    CG-CTF CRYPTO部分wp
    CG-CTF web部分wp
    快速排序算法的c++实现
    tornado当用户输入的URL无效时转入设定的页面
    sicily 4699. 简单哈希
    unbutu下Io language的解释器安装
  • 原文地址:https://www.cnblogs.com/malun/p/13921652.html
Copyright © 2011-2022 走看看