Skip to content

Commit

Permalink
Added async logging
Browse files Browse the repository at this point in the history
  • Loading branch information
GodCipher committed May 29, 2024
1 parent 3f8eaf4 commit f2e2e18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package dev.luzifer.spring.config;
package dev.luzifer.spring.config.async;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfiguration {
public class AsyncConfiguration implements AsyncConfigurer {

@Bean(name = "taskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
Expand All @@ -19,4 +21,9 @@ public ThreadPoolTaskExecutor taskExecutor() {
executor.initialize();
return executor;
}

@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncUncaughtExceptionHandlerImpl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.luzifer.spring.config.async;

import java.lang.reflect.Method;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;

@Slf4j
public class AsyncUncaughtExceptionHandlerImpl implements AsyncUncaughtExceptionHandler {

@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
log.error(
"Uncaught exception in async executed method {} with arguments {}",
method,
Arrays.toString(objects),
throwable);
}
}

0 comments on commit f2e2e18

Please sign in to comment.