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文件。

  • 相关阅读:
    bzoj 1031: [JSOI2007]字符加密Cipher
    python re模块实现计算器
    python sys模块和序列化模块
    python time时间模块
    python 发红包的小程序
    python ranndom模块及生成验证码
    python os模块练习题
    python os模块常用命令
    快速排序,归并排序
    选择排序和插入排序
  • 原文地址:https://www.cnblogs.com/malun/p/13921652.html
Copyright © 2011-2022 走看看