पता लगाने के लिए एक तरीका है।
यहाँ उदाहरण है कि कैसे आप LOGBack
// Here we create context
LoggerContext loggerContext = new LoggerContext();
// Initializer is used to enrich context with details
ContextInitializer contextInitializer = new ContextInitializer(loggerContext);
try {
// Get a configuration file from classpath
URL configurationUrl = Thread.currentThread().getContextClassLoader().getResource("custom-logback-configuration.xml");
if (configurationUrl == null) {
throw new IllegalStateException("Unable to find custom logback configuration file");
}
// Ask context initializer to load configuration into context
contextInitializer.configureByResource(configurationUrl);
// Here we get logger from context
logger = loggerContext.getLogger(LogReporter.class);
} catch (JoranException e) {
throw new RuntimeException("Unable to configure logger", e);
}
सामान्य में कॉन्फ़िगर कर सकते हैं अगर आप जानना चाहते हैं कि किसी भी SLF4J बैकएंड काम करता है चाहते हैं, तो आप उस बैकएंड से org.slf4j.impl.StaticLoggerBinder वर्ग स्रोत को देखने के लिए कर सकते हैं ।
लॉगरफ़ैक्टरी slf4j का हिस्सा है और क्लासैटिकॉगर बाइंडर का उपयोग करता है जो विभिन्न पुल कार्यान्वयन के साथ आता है, इसलिए मैं अभी भी इसके साथ slf4j के बाध्यकारी तंत्र का उपयोग कर रहा हूं। –
@JensSchauder: क्या बस 'नई LoggerContext()' बनाने और SLF4J एपीआई पूरी तरह से बचने के बारे में? –
मैं एक एपीआई, जहाँ मैं बिल्कुल SLF4j उपयोग नहीं कर सकते विकासशील कर रहा हूँ, यह स्टैंडअलोन logback उपयोग करना संभव है? – Akhilesh