use of ch.qos.logback.classic.spi.ILoggingEvent in project nifi by apache.
the class TestFileSystemRepository method testMinimalArchiveCleanupIntervalHonoredAndLogged.
@Test
public void testMinimalArchiveCleanupIntervalHonoredAndLogged() throws Exception {
// We are going to construct our own repository using different properties, so
// we need to shutdown the existing one.
shutdown();
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
ListAppender<ILoggingEvent> testAppender = new ListAppender<>();
testAppender.setName("Test");
testAppender.start();
root.addAppender(testAppender);
final Map<String, String> addProps = new HashMap<>();
addProps.put(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY, "1 millis");
final NiFiProperties localProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
repository = new FileSystemRepository(localProps);
repository.initialize(new StandardResourceClaimManager());
repository.purge();
boolean messageFound = false;
String message = "The value of nifi.content.repository.archive.cleanup.frequency property " + "is set to '1 millis' which is below the allowed minimum of 1 second (1000 milliseconds). " + "Minimum value of 1 sec will be used as scheduling interval for archive cleanup task.";
// keyword guards testAppender.list. Since we are accessing testAppender.list, we must do so in a thread-safe manner.
synchronized (testAppender) {
for (ILoggingEvent event : testAppender.list) {
String actualMessage = event.getFormattedMessage();
if (actualMessage.equals(message)) {
assertEquals(event.getLevel(), Level.WARN);
messageFound = true;
break;
}
}
}
assertTrue(messageFound);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project coffeenet-starter by coffeenet.
the class CoffeeNetLoggingAutoConfigurationTest method integration.
@Test
public void integration() {
final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
// Check File Appender
RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
// Check Gelf Appender
Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
assertThat(gelfAppender1.getServer(), is("localServer"));
assertThat(gelfAppender1.getProtocol(), is("TCP"));
assertThat(gelfAppender1.getPort(), is(1337));
assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project SmartApplianceEnabler by camueller.
the class Application method configureLogging.
public static void configureLogging(ch.qos.logback.classic.Level level, String file, boolean additive) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.getFrameworkPackages().add(ApplianceLogger.class.getPackage().getName());
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = null;
if (file != null) {
fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setFile(file);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
}
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("de.avanux");
if (fileAppender != null) {
logger.addAppender(fileAppender);
}
logger.setLevel(level);
logger.setAdditive(additive);
if (fileAppender != null) {
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(fileAppender);
}
logger.info("Logging configured with log level " + level);
// external classes
ch.qos.logback.classic.Logger loggerRetrieveRemoteDescriptors = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.fourthline.cling.protocol.RetrieveRemoteDescriptors");
loggerRetrieveRemoteDescriptors.setLevel(Level.ERROR);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project oap by oaplatform.
the class ZabbixAppender method dispatchEvents.
private void dispatchEvents() throws InterruptedException, IOException {
ILoggingEvent event = deque.takeFirst();
val events = new ArrayList<ILoggingEvent>();
events.add(event);
val list = new ArrayList<Data>();
addEvent(event, list);
while ((event = deque.pollFirst()) != null) {
events.add(event);
addEvent(event, list);
}
val request = new Request(list);
try {
if (!socketConnectionCouldBeEstablished()) {
throw new ConnectException();
}
addInfo(peerId + "connection established");
val outputStream = socket.getOutputStream();
val inputStream = socket.getInputStream();
addInfo("zabbixRequest = " + request);
ZabbixRequest.writeExternal(request, outputStream);
outputStream.flush();
val buf = new byte[1024];
val responseBaos = new ByteArrayOutputStream();
while (true) {
int read = inputStream.read(buf);
if (read <= 0) {
break;
}
responseBaos.write(buf, 0, read);
}
val bResponse = responseBaos.toByteArray();
if (bResponse.length < 13) {
addInfo("response.length < 13");
} else {
String jsonString = new String(bResponse, 13, bResponse.length - 13, StandardCharsets.UTF_8);
addInfo("response = " + jsonString);
}
} catch (IOException e) {
tryReAddingEventsToFrontOfQueue(events);
throw e;
} finally {
CloseUtil.closeQuietly(socket);
socket = null;
addInfo(peerId + "connection closed");
}
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project Singularity by HubSpot.
the class SingularityRunnerBaseLogging method buildFileAppender.
public FileAppender<ILoggingEvent> buildFileAppender(LoggerContext context, String file) {
FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setFile(file);
fileAppender.setContext(context);
fileAppender.setPrudent(true);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(primaryConfiguration.getLoggingPattern().or(baseConfiguration.getLoggingPattern()).or(JavaUtils.LOGBACK_LOGGING_PATTERN));
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
return fileAppender;
}
Aggregations