C# 의 nameof 메서드 처럼 심플하지는 않습니다 ;ㅁ;
@Service
public class TestService {
private final Logger logger = LogManager.getLogger(TestService.class);
private String getMethodName() {
return StackWalker.getInstance().walk(a -> a.skip(1).findFirst().get().getMethodName());
}
private void TestMethod() throws Exception {
logger.info("%s method Occurred".formatted(getMethodName()));
}
}
출력
[2025-03-29 20:30:38.687] INFO 57200 --- [nio-8082-exec-5] ission.test.service.TestService : TestMethod method Occurred