• 简单日志项目


    1、pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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>com.ebc</groupId>
        <artifactId>log-test</artifactId>
        <version>1.0</version>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
                <version>2.1.3.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <artifactId>log4j-to-slf4j</artifactId>
                        <groupId>org.apache.logging.log4j</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.6</version>
                <scope>provided</scope>
            </dependency>
    
        </dependencies>
    
    </project>

    2、logback.xml(可不写)

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration
    xmlns="http://ch.qos.logback/xml/ns/logback" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback
    https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd">

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
    <pattern>%msg%n</pattern>
    </encoder>
    </appender>
    <!-- TRACE < DEBUG < INFO < WARN < ERROR -->
    <root level="ERROR">
    <appender-ref ref="console"/>
    </root>
    <logger name="com.yst" level="DEBUG" />
    </configuration>

    3、ListenerTest1.java

    import lombok.extern.slf4j.Slf4j;
    
    @Slf4j
    public class ListenerTest1 {
        public static void main(String[] args) {
            log.info("{}","hello world");
        }
    }

    输出:

    09:23:44.765 [main] INFO com.ebc.ListenerTest1 - hello world

  • 相关阅读:
    PHP实现带有验证码的登陆注册
    XML
    自定义注解--Annotation
    URL编程
    SpringMvc表单标签库
    Socket编程
    网络编程
    其他流
    Spring MVC-视图解析器
    IDEA(JAVA)使用json
  • 原文地址:https://www.cnblogs.com/yaoyuan2/p/10582578.html
Copyright © 2020-2023  润新知