[slf4j-dev] [JIRA] Updates for SLF4J-528: Add a LoggerFactory method that infers caller class
QOS.CH (JIRA)
noreply-jira at qos.ch
Mon Dec 27 22:04:00 CET 2021
SLF4J / SLF4J-528 [Open]
Add a LoggerFactory method that infers caller class
==============================
Here's what changed in this issue in the last few minutes.
There is 1 comment.
View or comment on issue using this link
https://jira.qos.ch/browse/SLF4J-528
==============================
1 comment
------------------------------
Ceki Gülcü on 27/Dec/21 9:50 PM
I am aware of the following potential implementations:
Implementation 1
{code}
// Thread stack trace
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
{code}
Implementation 2
{code}
// use SecurityManager
private static final class ClassContextSecurityManager extends SecurityManager {
protected Class<?>[] getClassContext() {
return super.getClassContext();
}
}
private static ClassContextSecurityManager getSecurityManager() {
try {
return new ClassContextSecurityManager();
} catch (java.lang.SecurityException sm) {
return null;
}
}
ClassContextSecurityManager securityManager = getSecurityManager();
Class<?>[] trace = securityManager.getClassContext();
{code}
Implementation 3
{code}
// StackWalker API (new in Java9)
StackWalker WALKER = StackWalker.getInstance();
List<StackFrame> frames = WALKER.walk(s -> s.limit(4).collect(Collectors.toList()));
{code}
==============================
This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59)
More information about the slf4j-dev
mailing list