스프링 부트 시 디버깅로그 메시지를 끄는 방법
spring boot docs(https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html)에서 읽습니다.
application.properties에서 debug=true를 지정할 수도 있습니다.
따라서 application.properties에 debug=false를 추가하여 디버깅로그를 끌 수 있습니다.해봤는데 안 되더라고요.그럼 같은 의사선생님을 읽었네요
로깅 시스템은 응용 프로그램 수명 주기 초기에 초기화되므로 로그 속성은 를 통해 로드된 속성 파일에서 찾을 수 없습니다.
@PropertySource
주석"
그리고.
"로그가 초기화되기 전에
ApplicationContext
작성되어 있습니다.로깅을 제어할 수 없습니다.@PropertySources
봄에@Configuration
파일"
그리고.
"가능한 경우 로그 설정에 -spring variants를 사용하는 것을 권장합니다."라고 해서 다음 파일을 추가했습니다.
log4j-spring.properties
에src/main/resources
.
이 파일에서 나는 다음과 같이 덧붙였다.debug=false
(이 행만 표시되며 다른 것은 표시되지 않습니다만, 「현재 날짜」[메인] DEBUG ...메시지가 모두 표시됩니다.이 때문에, Spring Boot Application에서 디버깅메시지를 끄려면 어떻게 해야 하나요?어플리케이션에 전개합니다.메이븐으로 가는 추천할 만한 방법이 있나요?
2월 12일 추가
두 가지 주요 방법 1) Annotation Config Application Context를 사용하여 다음을 수행합니다.
public class DemoAppNoBoot {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
BatchConfiguration.class);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("job");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
} catch (Exception e) {
e.printStackTrace();
}
}
}
단편 출력:
08:26:18.713 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
08:26:18.744 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
08:26:18.744 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
08:26:18.947 [main] INFO o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@532760d8: startup date [Fri Feb 12 08:26:18 CST 2016]; root of context hierarchy
08:26:18.947 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext@532760d8: org.springframework.beans.factory.support.DefaultListableBeanFactory@50b494a6: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,batchConfiguration]; root of factory hierarchy
08:26:18.979 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean
...
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor'
08:26:32.560 [main] DEBUG o.s.s.a.ScheduledAnnotationBeanPostProcessor - Could not find default TaskScheduler bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:372) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
...
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL update
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?]
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - SQL update affected 1 rows
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.hsqldb.jdbc.JDBCConnection@33bbce9c]
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.hsqldb.jdbc.JDBCConnection@33bbce9c] after transaction
08:26:33.545 [pool-1-thread-1] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
08:26:33.545 [pool-1-thread-1] INFO o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=job1]] completed with the following parameters: [{}] and the following status: [COMPLETED]
Spring Application.run의 주요 메서드
@SpringBootApplication 퍼블릭클래스 데모어플리케이션 {public static void main(String[] args} {SpringApplication.run(BatchConfiguration.class, args);}}
전체 출력:
: Spring Boot :: (v1.3.1.RELEASE)
2016-02-12 08:02:36.145 INFO 12172 --- [ main] com.example.DemoApplication : Starting DemoApplication on GH-VDIKCISV252 with PID 12172 (C:\STS\wsRestTemplate\demo\target\classes started by e049447 in C:\STS\wsRestTemplate\demo)
2016-02-12 08:02:36.145 INFO 12172 --- [ main] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2016-02-12 08:02:36.473 INFO 12172 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4e4aea35: startup date [Fri Feb 12 08:02:36 CST 2016]; root of context hierarchy
2016-02-12 08:02:42.176 WARN 12172 --- [ main] o.s.c.a.ConfigurationClassEnhancer : @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2016-02-12 08:02:42.349 WARN 12172 --- [ main] o.s.c.a.ConfigurationClassEnhancer : @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2016-02-12 08:02:42.724 INFO 12172 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa'
2016-02-12 08:02:43.802 WARN 12172 --- [ main] o.s.b.c.l.AbstractListenerFactoryBean : org.springframework.batch.item.ItemReader is an interface. The implementing class will not be queried for annotation based listener configurations. If using @StepScope on a @Bean method, be sure to return the implementing class so listner annotations can be used.
2016-02-12 08:02:44.990 INFO 12172 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql]
2016-02-12 08:02:45.179 INFO 12172 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql] in 189 ms.
2016-02-12 08:02:46.804 INFO 12172 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-02-12 08:02:46.868 INFO 12172 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2016-02-12 08:02:46.962 INFO 12172 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2016-02-12 08:02:47.040 INFO 12172 --- [pool-2-thread-1] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2016-02-12 08:02:47.243 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2016-02-12 08:02:47.259 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2016-02-12 08:02:47.321 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{run.id=1}]
2016-02-12 08:02:47.368 INFO 12172 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2016-02-12 08:02:47.400 INFO 12172 --- [ main] com.example.CustomItemReader : read method - collecting the MYAPP2 out file names
2016-02-12 08:02:47.525 INFO 12172 --- [ main] com.example.CustomItemReader : read method - no file found
2016-02-12 08:02:47.556 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED]
2016-02-12 08:02:47.556 INFO 12172 --- [ main] com.example.DemoApplication : Started DemoApplication in 12.1 seconds (JVM running for 13.405)
2016-02-12 08:02:47.556 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{}]
2016-02-12 08:02:47.618 INFO 12172 --- [pool-2-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2016-02-12 08:02:47.634 INFO 12172 --- [pool-2-thread-1] com.example.CustomItemReader : read method - collecting the MYAPP2 out file names
2016-02-12 08:02:47.634 INFO 12172 --- [pool-2-thread-1] com.example.CustomItemReader : read method - no file found
2016-02-12 08:02:47.650 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{}] and the following status: [COMPLETED]
Batch Configuration 클래스
@Configuration
@ComponentScan("com.example")
@EnableBatchProcessing
@EnableAutoConfiguration
@EnableScheduling
@PropertySource("config.properties")
public class BatchConfiguration {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public Step step1(ItemReader<String> reader,
ItemProcessor<String, String> processor, ItemWriter<String> writer) {
return stepBuilderFactory.get("step1").<String, String> chunk(1) .reader(reader).processor(processor).writer(writer)
.allowStartIfComplete(true).build();
}
//I took out the rest of BatchConfiguration class
Application.properties(1줄만)
logging.level.*=OFF
추신: config.properties에는 비즈니스 로직에서 사용되는 경로 설정이 포함된 여러 속성 이름만 포함되어 있으므로 표시하지 않습니다.
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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.batch.version>3.0.6.RELEASE</spring.batch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<goals>install</goals>
<preparationGoals>install</preparationGoals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven 의존관계(의심할 수 있는 관련 관계):
logback-classic-1.1.3.jar
logback-core-1.1.3.jar
slf4j-api-1.7.13.jar
log4j-over-slf4j-1.7.13.jar
application.properties에서 logging.level을 추가할 수 있습니다.*=LEVEL'에서 'LEVEL'은 TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF 중 하나입니다. *는 패키지/클래스를 담당합니다.
예를들면
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
이는 루트 로거의 WARN level.org.springframework가 있음을 의미합니다.웹은 DEBUG 수준이지만 휴지 상태 파일은 모두 ERROR로 기록됩니다.
이 경우 모든 로깅을 끄려면 INFO, WARN, ERROR, FATAL 또는 OFF 중 하나의 레벨로 logging.level.root를 설정해야 합니다.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-custom-log-levels 를 참조해 주세요.
SpringMockMVC와 testLogging을 병용한 SpringRest Docs 사용 중.Gradle에서 show Standard Streams가 true로 설정되어 있는 경우 Spring은 정보와 디버깅로그로 콘솔을 어지럽힙니다.여기서 선택한 솔루션 위에 src/test/resources의 logback-test.xml을 작성해야 하는 Mkyong의 솔루션을 사용해야 했습니다.로그 레벨 OFF, ERROR, WARN, DEBUG 사용
logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework" level="ERROR"/>
</configuration>
log4j.properties 파일 또는 log4j.xml 파일 외에 maven pom.xml에 있는 이들 3개의 엔트리가 모두 필요합니다.log4j-module 아티팩트를 추가하면 문제가 즉시 해결됩니다.이것은 공통 로그오버에서 log4j로 apache-module 엔트리를 라우팅합니다.
네가 어떻게 불평할지는 모르겠지만 그 다리는 네가 필요한 것이다.
<!-- Log4J -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j.version}</version>
</dependency>
앱 메인에 다음 두 줄을 추가합니다.
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.ERROR);
필요한 Import는 다음과 같습니다.
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
XML 「Log4j2」스프링 부트.같은 에는 '마음껏'를 해야 했어요.logging
서브패키지도 마찬가지입니다.<Loggers>
삭제:
<Logger name="org.springframework.boot.autoconfigure.logging" level="error" />
또한 아래 패턴을 사용하여 콘솔에서 깔끔한 로그 결과를 볼 수도 있습니다.
logging.pattern.console=%clr(%d{yy-MM-dd E HH:mm:ss.SSS}){blue} %clr(%-5p) %clr(%logger{0}){blue} %clr(%m){faint}%n
중단점 아이콘을 클릭하고 확인란의 선택을 취소합니다.재실행 완료 후
언급URL : https://stackoverflow.com/questions/35353869/how-to-turn-off-debug-log-messages-in-spring-boot
'programing' 카테고리의 다른 글
약속.RxJs Observatible을 사용한 모든 동작? (0) | 2023.03.21 |
---|---|
긴 숫자에 의한 JSON 언마셜링에 부동소수점 번호가 부여됩니다. (0) | 2023.03.21 |
wordpress의 관리 사이드바에서 게시물을 제거하는 방법 (0) | 2023.03.21 |
제약 조건의 이름을 모를 때 Oracle에서 "not null" 제약 조건을 삭제하려면 어떻게 해야 합니까? (0) | 2023.03.21 |
Wait는 비동기 함수 내부의 예약된 단어 오류입니다. (0) | 2023.03.21 |