• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ContextSelectorStaticBinder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中ch.qos.logback.classic.util.ContextSelectorStaticBinder的典型用法代码示例。如果您正苦于以下问题:Java ContextSelectorStaticBinder类的具体用法?Java ContextSelectorStaticBinder怎么用?Java ContextSelectorStaticBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ContextSelectorStaticBinder类属于ch.qos.logback.classic.util包,在下文中一共展示了ContextSelectorStaticBinder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doFilter

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {

  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
  ContextJNDISelector sel = null;

  if (selector instanceof ContextJNDISelector) {
    sel = (ContextJNDISelector)selector;
    sel.setLocalContext(lc);
  }

  try {
    chain.doFilter(request, response);
  } finally {
    if (sel != null) {
      sel.removeLocalContext();
    }
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:21,代码来源:LoggerContextFilter.java


示例2: getDiscriminatingValue

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
/**
 * Return the name of the current context name as found in the logging event.
 */
public String getDiscriminatingValue(ILoggingEvent event) {
  ContextSelector selector = ContextSelectorStaticBinder.getSingleton()
      .getContextSelector();

  if (selector == null) {
    return defaultValue;
  }

  LoggerContext lc = selector.getLoggerContext();
  if (lc == null) {
    return defaultValue;
  }

  return lc.getName();
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:19,代码来源:JNDIBasedContextDiscriminator.java


示例3: getContextSelector

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
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;
}
 
开发者ID:Red5,项目名称:red5-server-common,代码行数:23,代码来源:Red5LoggerFactory.java


示例4: contextDestroyed

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
public void contextDestroyed(ServletContextEvent servletContextEvent) {
  String loggerContextName = null;
  
  try {
    Context ctx = JNDIUtil.getInitialContext();
    loggerContextName = (String) JNDIUtil.lookup(ctx, JNDI_CONTEXT_NAME);
  } catch (NamingException ne) {
  }
  
  if (loggerContextName != null) {
    System.out.println("About to detach context named " + loggerContextName);
    
    ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
    if(selector == null) {
      System.out.println("Selector is null, cannot detach context. Skipping.");
      return;
    }
    LoggerContext context = selector.getLoggerContext(loggerContextName);
    if (context != null) {
      Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME);
      logger.warn("Stopping logger context " + loggerContextName);
      selector.detachLoggerContext(loggerContextName);
      // when the web-app is destroyed, its logger context should be stopped
      context.stop();
    } else {
      System.out.println("No context named " + loggerContextName + " was found.");
    }
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:30,代码来源:ContextDetachingSCL.java


示例5: testCreateContext

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Test
public void testCreateContext() {
  MockInitialContext mic = MockInitialContextFactory.getContext();
  mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, "tata");
  
  LoggerFactory.getLogger(ContextDetachingSCLTest.class);
  
  ContextJNDISelector selector = (ContextJNDISelector)ContextSelectorStaticBinder.getSingleton().getContextSelector();
  Context context = selector.getLoggerContext();
  assertEquals("tata", context.getName());
  System.out.println(selector.getContextNames());
  assertEquals(2, selector.getCount());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:14,代码来源:ContextJNDISelectorTest.java


示例6: defaultContext

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Test
public void defaultContext() {
  MockInitialContext mic = MockInitialContextFactory.getContext();
  mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, null);

  ContextJNDISelector selector = (ContextJNDISelector)ContextSelectorStaticBinder.getSingleton().getContextSelector();
  Context context = selector.getLoggerContext();
  
  assertEquals("default", context.getName());    
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:11,代码来源:ContextJNDISelectorTest.java


示例7: testDetachWithMissingContext

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Test
public void testDetachWithMissingContext() {
  MockInitialContext mic = MockInitialContextFactory.getContext();
  mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, "tata");
  ContextJNDISelector selector = (ContextJNDISelector) ContextSelectorStaticBinder.getSingleton().getContextSelector();
  assertEquals("tata", selector.getLoggerContext().getName());

  mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, "titi");
  assertEquals("titi", selector.getLoggerContext().getName());
  contextDetachingSCL.contextDestroyed(null);

  assertEquals(2, selector.getCount());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:14,代码来源:ContextDetachingSCLTest.java


示例8: bind

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
public static void bind() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
    if (selector instanceof LogbackContextSelector) {
        tlsLoggingContext.set(context);
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:8,代码来源:LogbackContextSelector.java


示例9: contextDestroyed

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Override
public void contextDestroyed(ServletContextEvent sce) {
    configWatchDog.interrupt();
    ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
    String contextId = HttpUtils.getContextId(sce.getServletContext());
    selector.detachLoggerContext(contextId);
    configWatchDog.loggerContext.stop();
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:9,代码来源:LogbackConfigListener.java


示例10: testGetExistingContext

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Test
public void testGetExistingContext() {
  ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
  Context context = selector.getLoggerContext();
  assertEquals("toto", context.getName());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:7,代码来源:ContextJNDISelectorTest.java


示例11: testDetach

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Test
public void testDetach() {
  ContextJNDISelector selector = (ContextJNDISelector) ContextSelectorStaticBinder.getSingleton().getContextSelector();
  contextDetachingSCL.contextDestroyed(null);
  assertEquals(0, selector.getCount());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:7,代码来源:ContextDetachingSCLTest.java


示例12: environmentPrepared

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Override
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
public void environmentPrepared(ConfigurableEnvironment env) {
    this.buildInitializer(DefaultLoggingInitializer::new).initialize(env);

    this.loggerContext = ContextSelectorStaticBinder.getSingleton().getContextSelector().getDefaultLoggerContext();

    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    this.loggerContext.stop();
    this.loggerContext.reset();

    LevelChangePropagator lvlChangePropagator = new LevelChangePropagator();
    lvlChangePropagator.setContext(this.loggerContext);
    lvlChangePropagator.setResetJUL(true);
    this.loggerContext.addListener(lvlChangePropagator);

    this.loggerContext.putObject(SdcctApplication.BEAN_NAME, this.app);

    this.buildConversionRule(MessageMarkerConverter.WORD, MessageMarkerConverter.class);
    this.buildConversionRule(PriorityColorCompositeConverter.WORD, PriorityColorCompositeConverter.class);
    this.buildConversionRule(RootCauseThrowableProxyConverter.WORD, RootCauseThrowableProxyConverter.class);
    this.buildConversionRule(ThreadSectionConverter.WORD, ThreadSectionConverter.class);
    this.buildConversionRule(TxMdcConverter.WORD, TxMdcConverter.class);

    this.buildAppender(new ConsoleAppender<>(), AppenderType.CONSOLE, this.buildPatternLayoutEncoder(CONSOLE_APPENDER_PATTERN), true);

    this.buildFileAppender(AppenderType.FILE, this.buildPatternLayoutEncoder(FILE_APPENDER_PATTERN), new File(
        (this.logFileDir = this.app.getLogFileDirectory()), (this.app.getLogFileName() + FilenameUtils.EXTENSION_SEPARATOR + SdcctFileNameExtensions.LOG)));

    this.buildCachingAppender(AppenderType.LOGSTASH_FILE);

    this.buildLogger(org.slf4j.Logger.ROOT_LOGGER_NAME, Level.WARN, true, this.appenders.values());

    PropertySourceUtils.getSubProperties(env.getPropertySources(), SdcctPropertyNames.LOGGING_LOGGER_PREFIX).forEach((loggerName, loggerPropValue) -> {
        String[] loggerPropValueParts = StringUtils.split(((String) loggerPropValue), SdcctStringUtils.COLON, 2);
        Level loggerLvl = Level.toLevel(loggerPropValueParts[0].toUpperCase(), null);

        if (loggerLvl == null) {
            throw new ApplicationContextException(
                String.format("Unknown application (name=%s) logger (name=%s) level: %s", this.app.getName(), loggerName, loggerPropValueParts[0]));
        }

        this.buildLogger(loggerName, loggerLvl, false, ((loggerPropValueParts.length == 2)
            ? Stream.of(org.springframework.util.StringUtils.commaDelimitedListToStringArray(loggerPropValueParts[1])).map(loggerAppenderName -> {
                AppenderType loggerAppenderType = SdcctEnumUtils.findById(AppenderType.class, loggerAppenderName);

                if (!this.appenders.containsKey(loggerAppenderType)) {
                    throw new ApplicationContextException(String.format("Unknown application (name=%s) logger (name=%s) appender type (name=%s).",
                        this.app.getName(), loggerName, loggerAppenderName));
                }

                return this.appenders.get(loggerAppenderType);
            }).collect(Collectors.toList()) : this.appenders.values()));
    });

    StatusManager statusManager = this.loggerContext.getStatusManager();
    StatusUtil statusUtil = new StatusUtil(statusManager);
    long lastResetTime = statusUtil.timeOfLastReset();

    if (statusUtil.getHighestLevel(lastResetTime) >= Status.WARN) {
        StatusPrinter.print(statusManager, lastResetTime);

        throw new ApplicationContextException(String.format("Unable to initialize application (name=%s) logging.", this.app.getName()));
    }

    this.loggerContext.getLogger(LoggingInitializerRunListener.class).info(String.format("Application (name=%s) logging initialized.", this.app.getName()));
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:70,代码来源:LoggingInitializerRunListener.java


示例13: started

import ch.qos.logback.classic.util.ContextSelectorStaticBinder; //导入依赖的package包/类
@Override
public void started() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    this.app.addListeners(this);

    LoggerContext loggerContext = ContextSelectorStaticBinder.getSingleton().getContextSelector().getLoggerContext();

    loggerContext.stop();
    loggerContext.reset();

    String appName = this.app.getName(), consoleTty = System.getProperty(CrigttProperties.LOGGING_CONSOLE_TTY_NAME);
    CrigttLoggingInitializer loggingInit = buildComponent(CrigttLoggingInitializer.class, DefaultLoggingInitializer::new, this.app);

    loggerContext.setName(appName);
    loggerContext
        .putProperty(CrigttProperties.LOGGING_CONSOLE_TTY_NAME, ((consoleTty != null) ? consoleTty : Boolean.toString((System.console() != null))));
    loggerContext.putProperty(CrigttProperties.LOGGING_FILE_DIR_NAME, loggingInit.buildLogDirectory().getPath());
    loggerContext.putProperty(CrigttProperties.LOGGING_FILE_NAME_NAME, loggingInit.buildLogFileName());

    String configFileUrlPath = LOGBACK_CONFIG_FILE_URL_PATH_PREFIX + appName + FilenameUtils.EXTENSION_SEPARATOR + CrigttFileExtensions.GROOVY;
    URL configFileUrl;

    try {
        GafferConfigurator configurator = new GafferConfigurator(loggerContext);

        loggerContext.putObject(ClassicConstants.GAFFER_CONFIGURATOR_FQCN, configurator);

        configurator.run(IOUtils.toString((configFileUrl = ResourceUtils.getURL(configFileUrlPath))));
    } catch (IOException e) {
        throw new ApplicationContextException(String.format("Unable to process Logback configuration file (path=%s).", configFileUrlPath), e);
    }

    StatusManager statusManager = loggerContext.getStatusManager();
    StatusUtil statusUtil = new StatusUtil(statusManager);
    long lastResetTime = statusUtil.timeOfLastReset();

    if (statusUtil.getHighestLevel(lastResetTime) >= Status.WARN) {
        StatusPrinter.print(statusManager, lastResetTime);

        throw new ApplicationContextException(String.format("Unable to initialize Logback using configuration file (path=%s).", configFileUrlPath));
    }

    loggingInit.postProcessContext(loggerContext);

    loggerContext.getLogger(LoggingApplicationRunListener.class).info(
        String.format("Logging initialized (initializerClass=%s, configFileUrl=%s).", loggingInit.getClass().getName(), configFileUrl.toString()));
}
 
开发者ID:esacinc,项目名称:crigtt,代码行数:50,代码来源:LoggingApplicationRunListener.java



注:本文中的ch.qos.logback.classic.util.ContextSelectorStaticBinder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Method类代码示例发布时间:2022-05-23
下一篇:
Java ConfigurationProviderFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap