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); }
void secondPhase(String testId, String file, String stem, String compressionSuffix, int runLength, String prefix) { rfa1.stop(); if (stem != null) { File f = new File(file); f.setLastModified(currentTime); } StatusManager sm = context.getStatusManager(); sm.add(new InfoStatus("Time when rfa1 is stopped: " + new Date(currentTime), this)); sm.add(new InfoStatus("currentTime%1000=" + (currentTime % 1000), this)); initRollingFileAppender(rfa2, file); initPolicies(rfa2, tbrp2, randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}-%i.txt" + compressionSuffix, sizeThreshold, currentTime, 0); for (int i = runLength; i < runLength * 2; i++) { incCurrentTime(100); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); String msg = prefix + i; rfa2.doAppend(msg); addExpectedFileNamedIfItsTime(randomOutputDir, testId, msg, compressionSuffix); } }
public static void configure(LoggerContext lc) { StatusManager sm = lc.getStatusManager(); if(sm != null) { sm.add(new InfoStatus("Setting up default configuration.", lc)); } ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>(); 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(); Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.addAppender(ca); }
private URL findConfigFileURL(Context ctx, LoggerContext loggerContext) { StatusManager sm = loggerContext.getStatusManager(); String jndiEntryForConfigResource = JNDIUtil.lookup(ctx, JNDI_CONFIGURATION_RESOURCE); // Do we have a dedicated configuration file? if (jndiEntryForConfigResource != null) { sm.add(new InfoStatus("Searching for [" + jndiEntryForConfigResource + "]", this)); URL url = urlByResourceName(sm, jndiEntryForConfigResource); if (url == null) { String msg = "The jndi resource [" + jndiEntryForConfigResource + "] for context [" + loggerContext.getName() + "] does not lead to a valid file"; sm.add(new WarnStatus(msg, this)); } return url; } else { String resourceByConvention = conventionalConfigFileName(loggerContext .getName()); return urlByResourceName(sm, resourceByConvention); } }
/** {@inheritDoc} */ @Override public void configure(LoggerContext loggerContext) { StatusManager sm = loggerContext.getStatusManager(); if (sm != null) { sm.add(new InfoStatus("Setting up GreenPepper PHP Runner configuration.", loggerContext)); } ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>(); ca.setContext(loggerContext); ca.setName("console"); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(loggerContext); pl.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-36logger{36} - %msg%n"); pl.start(); ca.setEncoder(pl); ca.start(); Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.addAppender(ca); rootLogger.setLevel(Level.INFO); }
/** {@inheritDoc} */ @Override public void configure(LoggerContext loggerContext) { StatusManager sm = loggerContext.getStatusManager(); if (sm != null) { sm.add(new InfoStatus("Setting up default configuration.", loggerContext)); } ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>(); ca.setContext(loggerContext); ca.setName("console"); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(loggerContext); pl.setPattern("[%-5level] %msg%n"); pl.start(); ca.setEncoder(pl); ca.start(); Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.addAppender(ca); rootLogger.setLevel(Level.WARN); loggerContext.getLogger("com.greenpepper.maven.plugin").setLevel(Level.INFO); }
public void flush(AppenderType appenderType, Appender<ILoggingEvent> appender) { this.lock.lock(); try { this.appender = appender; int numCachedEvents = this.cache.size(); while (!this.cache.isEmpty()) { this.doAppend(this.cache.removeFirst()); } this.context.getStatusManager().add(new InfoStatus(String.format("Flushed %d cached application (name=%s) logging event(s) to appender (type=%s).", numCachedEvents, this.app.getName(), appenderType.getId()), appender)); } finally { this.lock.unlock(); } }
public static void configure(LoggerContext loggerContext) { loggerContext.reset(); StatusManager sm = loggerContext.getStatusManager(); if (sm != null) { sm.add(new InfoStatus("Setting up default Pipes configuration.", loggerContext)); } ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>(); ca.setContext(loggerContext); ca.setWithJansi(true); ca.setName("console"); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setCharset(Charset.forName("UTF-8")); pl.setContext(loggerContext); //pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); pl.setPattern("%msg%n"); pl.start(); ca.setEncoder(pl); ca.start(); ch.qos.logback.classic.Logger rootLogger = loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); rootLogger.setLevel(Level.INFO); rootLogger.addAppender(ca); }
@Override public void start() throws LifecycleException { super.start(); ctx.start(); if (filename == null) { filename = OptionHelper.getSystemProperty("logbackAccess.configurationFile"); if (filename == null) { filename = DEFAULT_CONFIG_FILE; } ctx.getStatusManager().add(new InfoStatus("filename property not set. Assuming [" + filename + "]", this)); } // TODO: Support classpath config File configFile = new File(filename); if (configFile.exists()) { try { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(ctx); jc.doConfigure(filename); } catch (JoranException e) { // TODO can we do better than printing a stack trace on syserr? e.printStackTrace(); } } else { ctx.getStatusManager().add(new WarnStatus("[" + filename + "] does not exist", this)); } if (!quiet) { StatusPrinter.print(ctx.getStatusManager()); } }
private void createLogGroup() { try { awsLogs.createLogGroup(new CreateLogGroupRequest().withLogGroupName(logGroupName)); } catch (final ResourceAlreadyExistsException e) { addStatus(new InfoStatus(e.getMessage(), this)); } }
private void createLogStream() { try { awsLogs.createLogStream(new CreateLogStreamRequest().withLogGroupName(logGroupName).withLogStreamName(logStreamName)); } catch (final ResourceAlreadyExistsException e) { addStatus(new InfoStatus(e.getMessage(), this)); } }
/** * 心跳检测开始 */ 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); }
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.toString() + "]", this.loggerContext)); this.multiplicityWarning(resourceName, classLoader); } }
private void postSuccessfulWrite() { if (recoveryCoordinator != null) { recoveryCoordinator = null; statusCount = 0; addStatus(new InfoStatus("Recovered from IO failure on " + getDescription(), this)); } }
void addStatusIfCountNotOverLimit(Status s) { ++statusCount; if (statusCount < STATUS_COUNT_LIMIT) { addStatus(s); } if (statusCount == STATUS_COUNT_LIMIT) { addStatus(s); addStatus(new InfoStatus("Will supress future messages regarding " + getDescription(), this)); } }
@Test public void testBasic() { Context context = new ContextBase(); context.getStatusManager().add(new InfoStatus("test", this)); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("|-INFO in "+this.getClass().getName())); }
@Test public void testNested() { Status s0 = new ErrorStatus("test0", this); Status s1 = new InfoStatus("test1", this); Status s11 = new InfoStatus("test11", this); Status s12 = new InfoStatus("test12", this); s1.add(s11); s1.add(s12); Status s2 = new InfoStatus("test2", this); Status s21 = new InfoStatus("test21", this); Status s211 = new WarnStatus("test211", this); Status s22 = new InfoStatus("test22", this); s2.add(s21); s2.add(s22); s21.add(s211); Context context = new ContextBase(); context.getStatusManager().add(s0); context.getStatusManager().add(s1); context.getStatusManager().add(s2); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("+ INFO in "+this.getClass().getName())); assertTrue(result.contains("+ WARN in "+this.getClass().getName())); assertTrue(result.contains(" |-WARN in "+this.getClass().getName())); }
@Test public void testWithException() { Status s0 = new ErrorStatus("test0", this); Status s1 = new InfoStatus("test1", this, new Exception("testEx")); Status s11 = new InfoStatus("test11", this); Status s12 = new InfoStatus("test12", this); s1.add(s11); s1.add(s12); Status s2 = new InfoStatus("test2", this); Status s21 = new InfoStatus("test21", this); Status s211 = new WarnStatus("test211", this); Status s22 = new InfoStatus("test22", this); s2.add(s21); s2.add(s22); s21.add(s211); Context context = new ContextBase(); context.getStatusManager().add(s0); context.getStatusManager().add(s1); context.getStatusManager().add(s2); StatusPrinter.print(context); String result = outputStream.toString(); assertTrue(result.contains("|-ERROR in "+this.getClass().getName())); assertTrue(result.contains("+ INFO in "+this.getClass().getName())); assertTrue(result.contains("ch.qos.logback.core.util.StatusPrinterTest.testWithException")); }
private URL urlByResourceName(StatusManager sm, String resourceName) { sm.add(new InfoStatus("Searching for [" + resourceName + "]", this)); URL url = Loader.getResource(resourceName, Loader.getTCL()); if (url != null) { return url; } return Loader.getResourceBySelfClassLoader(resourceName); }
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); } }
@Test(timeout = 4000L) public void scan_LOGBACK_474() throws JoranException, IOException, InterruptedException { File file = new File(SCAN_LOGBACK_474_FILE_AS_STR); configure(file); RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(file, UpdateType.TOUCH); harness.execute(runnableArray); loggerContext.getStatusManager().add( new InfoStatus("end of execution ", this)); verify(expectedResets); }
public static void initLogback() { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusManager statusManager = loggerContext.getStatusManager(); if (statusManager != null) { statusManager.add(new InfoStatus("Setting up logger configuration.", loggerContext)); } final PatternLayout layout = new PatternLayout(); layout.setContext(loggerContext); layout.setPattern("%msg%n"); layout.start(); AppenderBase<ILoggingEvent> appender = new AppenderBase<ILoggingEvent>() { @Override protected void append(ILoggingEvent event) { String message = layout.doLayout(event); LogHelper.appendLogEntry(event.getTimeStamp(), convertLevel(event.getLevel()), event.getLoggerName(), event.getThreadName(), message); } }; appender.setContext(loggerContext); appender.setName(LOGBACK_APPENDER_NAME); appender.start(); Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.addAppender(appender); }
public void addInfo(String msg) { addStatus(new InfoStatus(msg, getOrigin())); }
public void addInfo(String msg, Throwable ex) { addStatus(new InfoStatus(msg, getOrigin(), ex)); }
public void addInfo(String msg) { addStatus(new InfoStatus(msg, getDeclaredOrigin())); }
public void addInfo(String msg, Throwable ex) { addStatus(new InfoStatus(msg, getDeclaredOrigin(), ex)); }
static void addInfo(Context context, String msg) { addStatus(context, new InfoStatus(msg, origin)); }
void addInfo(String msg, Object o) { loggerContext.getStatusManager().add(new InfoStatus(msg, o)); }
@Override public void startInternal() throws LifecycleException { executorService = ExecutorServiceUtil.newExecutorService(); if (filename == null) { String tomcatBaseProperty = OptionHelper .getSystemProperty("catalina.base"); filename = tomcatBaseProperty + File.separatorChar + DEFAULT_CONFIG_FILE; File baseConfigFile = new File(filename); if (!baseConfigFile.exists()) { String tomcatHomeProperty = OptionHelper .getSystemProperty("catalina.home"); filename = tomcatHomeProperty + File.separatorChar + DEFAULT_CONFIG_FILE; } getStatusManager().add( new InfoStatus("filename property not set. Assuming [" + filename + "]", this)); } File configFile = new File(filename); if (configFile.exists()) { try { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(this); jc.doConfigure(filename); } catch (JoranException e) { // TODO can we do better than printing a stack trace on syserr? e.printStackTrace(); } } else { getStatusManager().add( new WarnStatus("[" + filename + "] does not exist", this)); } if (!quiet) { StatusPrinter.print(getStatusManager()); } started = true; setState(LifecycleState.STARTING); }
private void addInfo(String msg) { getStatusManager().add(new InfoStatus(msg, this)); }
/** {@inheritDoc} */ @Override public void addInfo(String msg) { context.getStatusManager().add(new InfoStatus(msg, context)); }
/** {@inheritDoc} */ @Override public void addInfo(String msg, Throwable ex) { context.getStatusManager().add(new InfoStatus(msg, context, ex)); }