ch.qos.logback.core.status.StatusManager Java Examples
The following examples show how to use
ch.qos.logback.core.status.StatusManager.
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: ContextInitializer.java From stategen with GNU Affero General Public License v3.0 | 6 votes |
public void configureByResource(URL url) throws JoranException { if (url == null) { throw new IllegalArgumentException("URL argument cannot be null"); } final String urlString = url.toString(); if (urlString.endsWith("groovy")) { if (EnvUtil.isGroovyAvailable()) { // avoid directly referring to GafferConfigurator so as to avoid // loading groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214 GafferUtil.runGafferConfiguratorOn(loggerContext, this, url); } else { StatusManager sm = loggerContext.getStatusManager(); sm.add(new ErrorStatus("Groovy classes are not available on the class path. ABORTING INITIALIZATION.", loggerContext)); } } else if (urlString.endsWith("xml")) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); } else { throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml"); } }
Example #2
Source File: KonkerContextInitializer.java From konker-platform with Apache License 2.0 | 6 votes |
private void multiplicityWarning(String resourceName, ClassLoader classLoader) { Set urlSet = null; StatusManager sm = this.loggerContext.getStatusManager(); try { urlSet = Loader.getResourceOccurrenceCount(resourceName, classLoader); } catch (IOException var7) { sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + ']', this.loggerContext, var7)); } if (urlSet != null && urlSet.size() > 1) { sm.add(new WarnStatus("Resource [" + resourceName + "] occurs multiple times on the classpath.", this.loggerContext)); Iterator i$ = urlSet.iterator(); while (i$.hasNext()) { URL url = (URL) i$.next(); sm.add(new WarnStatus("Resource [" + resourceName + "] occurs at [" + url + ']', this.loggerContext)); } } }
Example #3
Source File: KonkerLoggerBasicConfigurator.java From konker-platform with Apache License 2.0 | 6 votes |
public static void configure(KonkerLoggerContext lc) { StatusManager sm = lc.getStatusManager(); if(sm != null) { sm.add(new InfoStatus("Setting up default configuration.", lc)); } ConsoleAppender ca = new ConsoleAppender(); ca.setContext(lc); ca.setName("console"); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(lc); pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); pl.start(); ca.setEncoder(pl); ca.start(); KonkerLogger rootLogger = lc.getLogger("ROOT"); rootLogger.addAppender(ca); }
Example #4
Source File: ContextInitializer.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
public URL findURLOfDefaultConfigurationFile(boolean updateStatus) throws IOException { StatusManager sm = loggerContext.getStatusManager(); ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this); URL url = null; url = loadURLFormPropertiesFile(myClassLoader, updateStatus); if (url != null) { sm.add(new InfoStatus("装载文件:"+url, loggerContext) ); return url; } sm.add(new ErrorStatus("从"+application_properties+" 装载文件不成功,不存在!", loggerContext) ); url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus); if (url != null) { return url; } url = getResource(GROOVY_AUTOCONFIG_FILE, myClassLoader, updateStatus); if (url != null) { return url; } url = getResource(TEST_AUTOCONFIG_FILE, myClassLoader, updateStatus); if (url != null) { return url; } url = getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus); sm.add(new InfoStatus(""+url, loggerContext) ); return url; }
Example #5
Source File: ContextInitializer.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
private void statusOnResourceSearch(String resourceName, ClassLoader classLoader, URL url) { StatusManager sm = loggerContext.getStatusManager(); if (url == null) { sm.add(new InfoStatus("Could NOT find resource [" + resourceName + "]", loggerContext)); } else { sm.add(new InfoStatus("Found resource [" + resourceName + "] at [" + url.toString() + "]", loggerContext)); multiplicityWarning(resourceName, classLoader); } }
Example #6
Source File: ContextInitializer.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
private void multiplicityWarning(String resourceName, ClassLoader classLoader) { Set<URL> urlSet = null; StatusManager sm = loggerContext.getStatusManager(); try { urlSet = Loader.getResources(resourceName, classLoader); } catch (IOException e) { sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + "]", loggerContext, e)); } if (urlSet != null && urlSet.size() > 1) { sm.add(new WarnStatus("Resource [" + resourceName + "] occurs multiple times on the classpath.", loggerContext)); for (URL url : urlSet) { sm.add(new WarnStatus("Resource [" + resourceName + "] occurs at [" + url.toString() + "]", loggerContext)); } } }
Example #7
Source File: TestAppender.java From aliyun-log-logback-appender with Apache License 2.0 | 5 votes |
@AfterClass public static void checkStatusList() { sleep(); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusManager statusManager = lc.getStatusManager(); List<Status> statusList = statusManager.getCopyOfStatusList(); for (Status status : statusList) { int level = status.getLevel(); assertNotEquals(status.getMessage(), Status.ERROR, level); assertNotEquals(status.getMessage(), Status.WARN, level); } }
Example #8
Source File: ExceptionConverterTest.java From styx with Apache License 2.0 | 5 votes |
@Test public void errorsIfTargetClassPropertyIsEmpty() throws Exception { ContextBase contextBase = new ContextBase(); StatusManager statusManager = mock(StatusManager.class); contextBase.setStatusManager(statusManager); ExceptionConverter converter = newExceptionConverter(contextBase); converter.getContext() .putProperty(TARGET_CLASSES_PROPERTY_NAME, ""); ILoggingEvent loggingEvent = newErrorLoggingEvent(new TargetClass().blow()); converter.convert(loggingEvent); verify(statusManager).add(any(ErrorStatus.class)); }
Example #9
Source File: KonkerLoggerContext.java From konker-platform with Apache License 2.0 | 5 votes |
private void resetStatusListeners() { StatusManager sm = this.getStatusManager(); Iterator i$ = sm.getCopyOfStatusListenerList().iterator(); while(i$.hasNext()) { StatusListener sl = (StatusListener)i$.next(); sm.remove(sl); } }
Example #10
Source File: KonkerContextInitializer.java From konker-platform with Apache License 2.0 | 5 votes |
private void statusOnResourceSearch(String resourceName, ClassLoader classLoader, URL url) { StatusManager sm = this.loggerContext.getStatusManager(); if (url == null) { sm.add(new InfoStatus("Could NOT find resource [" + resourceName + ']', this.loggerContext)); } else { sm.add(new InfoStatus("Found resource [" + resourceName + "] at [" + url + ']', this.loggerContext)); this.multiplicityWarning(resourceName, classLoader); } }
Example #11
Source File: RequestContextExportingAppenderTest.java From armeria with Apache License 2.0 | 5 votes |
@AfterEach void tearDown() { final Logger logger = (Logger) LoggerFactory.getLogger(getClass()); final StatusManager sm = rootLogger.getLoggerContext().getStatusManager(); int count = 0; for (Status s : sm.getCopyOfStatusList()) { final int level = s.getEffectiveLevel(); if (level == Status.INFO) { continue; } if (s.getMessage().contains(InternalLoggerFactory.class.getName())) { // Skip the warnings related with Netty. continue; } count++; switch (level) { case Status.WARN: if (s.getThrowable() != null) { logger.warn(s.getMessage(), s.getThrowable()); } else { logger.warn(s.getMessage()); } break; case Status.ERROR: if (s.getThrowable() != null) { logger.warn(s.getMessage(), s.getThrowable()); } else { logger.warn(s.getMessage()); } break; } } if (count > 0) { fail("Appender raised an exception."); } }
Example #12
Source File: ContextInitializer.java From stategen with GNU Affero General Public License v3.0 | 4 votes |
private URL loadURLFormPropertiesFile(ClassLoader myClassLoader, boolean updateStatus) throws IOException { StatusManager sm = loggerContext.getStatusManager(); sm.add(new InfoStatus("正在读取:" + application_properties, loggerContext)); URL application_url=getResource(application_properties, myClassLoader, updateStatus); if (application_url==null) { return null; } String applicationPropertiesPath = application_url.getPath(); Properties prop = new Properties(); @Cleanup InputStream in = null; try { sm.add(new InfoStatus(applicationPropertiesPath, loggerContext) ); in=myClassLoader.getResourceAsStream(application_properties); prop.load(in); if (!prop.containsKey(logback_config_xml_key)) { sm.add(new ErrorStatus(applicationPropertiesPath+" 文件中没有键:"+logback_config_xml_key, loggerContext) ); return null; } sm.add(new InfoStatus(applicationPropertiesPath+" 文件中有键:"+logback_config_xml_key, loggerContext) ); String logbackFile = prop.getProperty(logback_config_xml_key); logbackFile = logbackFile.trim(); if (logbackFile==null || logbackFile.isEmpty()) { sm.add(new ErrorStatus(applicationPropertiesPath+" 文件中键:"+logback_config_xml_key+" 为空!", loggerContext) ); return null; } sm.add(new InfoStatus(applicationPropertiesPath+" 文件中键:"+logback_config_xml_key+" 值为:"+logbackFile, loggerContext) ); logbackFile = OSUtil.getRealUriPathByOs(logbackFile); sm.add(new InfoStatus("Found logback configration :"+logbackFile, loggerContext) ); sm.add(new InfoStatus("加载真正的Logback配置文件:"+logbackFile, loggerContext)); URL url = new URL(logbackFile); return url; } catch (IOException e) { sm.add(new ErrorStatus( "Failed to get url list for resource [" + applicationPropertiesPath + "]", loggerContext, e)); } return null; }