ch.qos.logback.core.status.InfoStatus Java Examples

The following examples show how to use ch.qos.logback.core.status.InfoStatus. 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: KonkerLoggerBasicConfigurator.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: ContextInitializer.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #3
Source File: ContextInitializer.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #4
Source File: KafkaAppender.java    From SkyEye with GNU General Public License v3.0 5 votes vote down vote up
/**
     * 心跳检测开始
     */
    public void heartbeatStart() {
        // 心跳检测定时器初始化
        this.timer = new Timer();
        this.timer.schedule(new TimerTask() {
            @Override
            public void run() {
                byte[] key = ByteBuffer.allocate(4).putInt(Constants.HEARTBEAT_KEY.hashCode()).array();
                final ProducerRecord<byte[], String> record = new ProducerRecord<>(topic, key, Constants.HEARTBEAT_VALUE);

                // java 8 lambda
//                LazySingletonProducer.getInstance(config).send(record, (RecordMetadata recordMetadata, Exception e) -> {
                // logic code
//                });

                LazySingletonProducer.getInstance(config).send(record, new Callback() {
                    @Override
                    public void onCompletion(RecordMetadata recordMetadata, Exception e) {
                        if (null == e) {
                            // 更新flag状态
                            flag.compareAndSet(false, true);
                            // 如果没有发生异常, 说明kafka从异常状态切换为正常状态, 将开始状态设置为true
                            started = true;
                            addStatus(new InfoStatus("kafka send normal in appender", this, e));
                            // 关闭心跳检测机制
                            KafkaAppender.this.heartbeatStop();
                            zkRegister.write(Constants.SLASH + app + Constants.SLASH + host, NodeMode.EPHEMERAL,
                                    String.valueOf(Constants.APP_APPENDER_RESTART_KEY + Constants.SEMICOLON + System.currentTimeMillis()) + Constants.SEMICOLON + SysUtil.userDir);
                        }
                    }
                });
            }
        }, 10000,60000);
    }
 
Example #5
Source File: KonkerContextInitializer.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: ContextInitializer.java    From stategen with GNU Affero General Public License v3.0 4 votes vote down vote up
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;
}