use of ch.qos.logback.classic.spi.LoggingEvent in project cdap by caskdata.
the class CDAPLogAppenderTest method testCDAPLogAppender.
@Test
public void testCDAPLogAppender() throws Exception {
int syncInterval = 1024 * 1024;
CDAPLogAppender cdapLogAppender = new CDAPLogAppender();
cdapLogAppender.setSyncIntervalBytes(syncInterval);
cdapLogAppender.setMaxFileLifetimeMs(TimeUnit.DAYS.toMillis(1));
cdapLogAppender.setMaxFileSizeInBytes(104857600);
cdapLogAppender.setDirPermissions("700");
cdapLogAppender.setFilePermissions("600");
cdapLogAppender.setFileRetentionDurationDays(1);
cdapLogAppender.setLogCleanupIntervalMins(10);
cdapLogAppender.setFileCleanupTransactionTimeout(30);
AppenderContext context = new LocalAppenderContext(injector.getInstance(DatasetFramework.class), injector.getInstance(TransactionSystemClient.class), injector.getInstance(LocationFactory.class), new NoOpMetricsCollectionService());
context.start();
cdapLogAppender.setContext(context);
cdapLogAppender.start();
FileMetaDataReader fileMetaDataReader = injector.getInstance(FileMetaDataReader.class);
LoggingEvent event = new LoggingEvent("co.cask.Test", (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME), Level.ERROR, "test message", null, null);
Map<String, String> properties = new HashMap<>();
properties.put(NamespaceLoggingContext.TAG_NAMESPACE_ID, "default");
properties.put(ApplicationLoggingContext.TAG_APPLICATION_ID, "testApp");
properties.put(FlowletLoggingContext.TAG_FLOW_ID, "testFlow");
properties.put(FlowletLoggingContext.TAG_FLOWLET_ID, "testFlowlet");
event.setMDCPropertyMap(properties);
cdapLogAppender.doAppend(event);
cdapLogAppender.stop();
context.stop();
try {
List<LogLocation> files = fileMetaDataReader.listFiles(cdapLogAppender.getLoggingPath(properties), 0, Long.MAX_VALUE);
Assert.assertEquals(1, files.size());
LogLocation logLocation = files.get(0);
Assert.assertEquals(LogLocation.VERSION_1, logLocation.getFrameworkVersion());
Assert.assertTrue(logLocation.getLocation().exists());
CloseableIterator<LogEvent> logEventCloseableIterator = logLocation.readLog(Filter.EMPTY_FILTER, 0, Long.MAX_VALUE, Integer.MAX_VALUE);
int logCount = 0;
while (logEventCloseableIterator.hasNext()) {
logCount++;
LogEvent logEvent = logEventCloseableIterator.next();
Assert.assertEquals(event.getMessage(), logEvent.getLoggingEvent().getMessage());
}
logEventCloseableIterator.close();
Assert.assertEquals(1, logCount);
// checking permission
String expectedPermissions = "rw-------";
for (LogLocation file : files) {
Location location = file.getLocation();
Assert.assertEquals(expectedPermissions, location.getPermissions());
}
} catch (Exception e) {
Assert.fail();
}
}
use of ch.qos.logback.classic.spi.LoggingEvent in project cdap by caskdata.
the class DistributedLogFrameworkTest method createLoggingEvent.
/**
* Creates an {@link ILoggingEvent}.
*/
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp) {
LoggingEvent event = new LoggingEvent();
event.setLevel(level);
event.setLoggerName(loggerName);
event.setMessage(message);
event.setTimeStamp(timestamp);
return event;
}
use of ch.qos.logback.classic.spi.LoggingEvent in project cdap-ingest by caskdata.
the class FileTailerMetricsProcessor method writeMetrics.
/**
* Writes metric to metrics file.
*
* @param logger the logger
* @param appender the file appender
* @param currentDate the date of creating this metric
*/
private void writeMetrics(ch.qos.logback.classic.Logger logger, RollingFileAppender appender, String currentDate) {
LOG.debug("Start writing metric with date {} to file ..", currentDate);
String metric = new StringBuilder(currentDate).append(",").append(flowName).append(",").append(fileName).append(",").append(totalEventsReadPerFile.get()).append(",").append(totalEventsIngestedPerFile.get()).append(",").append(minEventSizePerFile.get()).append(",").append(calculateAverage(totalEventSizePerFile.get(), eventsPerFile.get())).append(",").append(maxEventSizePerFile.get()).append(",").append(minWriteLatencyPerStream.get()).append(",").append(calculateAverage(totalWriteLatencyPerStream.get(), writesPerStream.get())).append(",").append(maxWriteLatencyPerStream.get()).toString();
appender.doAppend(new LoggingEvent(loggerClass, logger, null, metric, null, null));
LOG.debug("Successfully wrote metric with date: {}", currentDate);
}
use of ch.qos.logback.classic.spi.LoggingEvent in project dropwizard by dropwizard.
the class DropwizardSlf4jRequestLog method write.
@Override
public void write(String entry) throws IOException {
final LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setLoggerName("http.request");
event.setMessage(entry);
event.setTimeStamp(System.currentTimeMillis());
appenders.appendLoopOnAppenders(event);
}
use of ch.qos.logback.classic.spi.LoggingEvent in project spring-boot by spring-projects.
the class ColorConverterTests method setup.
@Before
public void setup() {
this.converter = new ColorConverter();
this.event = new LoggingEvent();
}
Aggregations