ch.qos.logback.classic.util.ContextSelectorStaticBinder Java Examples
The following examples show how to use
ch.qos.logback.classic.util.ContextSelectorStaticBinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LOGBackConfigurer.java From styx with Apache License 2.0 | 6 votes |
/** * Initialize LOGBack from the given URL. * * @param url the url pointing to the location of the config file. * @param installJULBridge set to true to install SLF4J JUL bridge * @throws IllegalArgumentException if the url points to a non existing location or an error occurs during the parsing operation. */ public static void initLogging(URL url, boolean installJULBridge) { StaticLoggerBinder.getSingleton(); ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector(); LoggerContext loggerContext = selector.getLoggerContext(); loggerContext.stop(); ContextInitializer ctxi = new ContextInitializer(loggerContext); try { ctxi.configureByResource(url); loggerContext.start(); if (installJULBridge) { //uninstall already present handlers we want to //continue logging through SLF4J after this point Logger l = LogManager.getLogManager().getLogger(""); for (Handler h : l.getHandlers()) { l.removeHandler(h); } SLF4JBridgeHandler.install(); } } catch (JoranException e) { throw new IllegalArgumentException("exception while initializing LOGBack", e); } }
Example #2
Source File: Red5LoggerFactory.java From red5-server-common with Apache License 2.0 | 6 votes |
public static ContextSelector getContextSelector() { if (useLogback) { ContextSelectorStaticBinder contextSelectorBinder = ContextSelectorStaticBinder.getSingleton(); ContextSelector selector = contextSelectorBinder.getContextSelector(); if (selector == null) { if (DEBUG) { System.err.println("Context selector was null, creating default context"); } LoggerContext defaultLoggerContext = new LoggerContext(); defaultLoggerContext.setName(CoreConstants.DEFAULT_CONTEXT_NAME); try { contextSelectorBinder.init(defaultLoggerContext, null); selector = contextSelectorBinder.getContextSelector(); } catch (Exception e) { e.printStackTrace(); } } //System.out.printf("Context selector: %s%n", selector.getClass().getName()); return selector; } return null; }
Example #3
Source File: LogbackCapture.java From emissary with Apache License 2.0 | 5 votes |
private static Logger getLogbackLogger(String name, Level level) { if (name == null || name.isEmpty()) name = ROOT_LOGGER_NAME; if (level == null) level = ALL; Logger logger = ContextSelectorStaticBinder.getSingleton().getContextSelector().getDefaultLoggerContext().getLogger(name); logger.setLevel(level); return logger; }
Example #4
Source File: LogbackCapture.java From emissary with Apache License 2.0 | 5 votes |
private static Encoder<ILoggingEvent> buildEncoder(String layoutPattern) { if (layoutPattern == null) layoutPattern = "[%p] %m%n"; PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setPattern(layoutPattern); encoder.setCharset(Charset.forName("UTF-16")); encoder.setContext(ContextSelectorStaticBinder.getSingleton().getContextSelector().getDefaultLoggerContext()); encoder.start(); return encoder; }
Example #5
Source File: LogbackCapture.java From emissary with Apache License 2.0 | 5 votes |
private static OutputStreamAppender<ILoggingEvent> buildAppender(final Encoder<ILoggingEvent> encoder, final OutputStream outputStream) { OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<ILoggingEvent>(); appender.setName("logcapture"); appender.setContext(ContextSelectorStaticBinder.getSingleton().getContextSelector().getDefaultLoggerContext()); appender.setEncoder(encoder); appender.setOutputStream(outputStream); appender.start(); return appender; }
Example #6
Source File: LOGBackConfigurer.java From styx with Apache License 2.0 | 5 votes |
/** * Shut down LOGBack. * This isn't strictly necessary, but recommended for shutting down * logback in a scenario where the host VM stays alive (for example, when * shutting down an application in a J2EE environment). * * @param uninstallJULBridge should an attempt be made to uninstall the JUL bridge */ public static void shutdownLogging(boolean uninstallJULBridge) { ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector(); LoggerContext loggerContext = selector.getLoggerContext(); String loggerContextName = loggerContext.getName(); LoggerContext context = selector.detachLoggerContext(loggerContextName); if (uninstallJULBridge) { SLF4JBridgeHandler.uninstall(); } context.stop(); }