use of com.yahoo.log.event.Event in project vespa by vespa-engine.
the class LogMessageTestCase method testEvents.
/**
* Read in some events and make sure we are able to identify
* them as such.
*/
@Test
public void testEvents() throws IOException {
String eventfile = "src/test/files/event.txt.gz";
BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(eventfile))));
for (String line = br.readLine(); line != null; line = br.readLine()) {
try {
LogMessage m = LogMessage.parseNativeFormat(line);
try {
Event event = m.getEvent();
assertNotNull(event);
} catch (MalformedEventException evx) {
fail();
}
} catch (InvalidLogFormatException e) {
fail();
}
}
}
use of com.yahoo.log.event.Event in project vespa by vespa-engine.
the class MetricsFilterTestCase method testValueEvents.
@Test
public void testValueEvents() throws InvalidLogFormatException, IOException {
MetricsFilter filter = new MetricsFilter();
String filename = "src/test/files/value-events.txt";
BufferedReader br = new BufferedReader(new FileReader(filename));
for (String line = br.readLine(); line != null; line = br.readLine()) {
LogMessage m = LogMessage.parseNativeFormat(line);
assertNotNull(m);
try {
Event event = m.getEvent();
assertNotNull(event);
} catch (MalformedEventException e) {
fail();
}
if (filter.isLoggable(m)) {
assertTrue(true);
} else {
fail();
}
}
}
use of com.yahoo.log.event.Event in project vespa by vespa-engine.
the class VespaFormatter method format.
public String format(LogRecord r) {
// initial guess
StringBuilder sbuf = new StringBuilder(300);
String levelName = LogLevel.getVespaLogLevel(r.getLevel()).toString().toLowerCase();
String component = r.getLoggerName();
// format the time
VespaFormat.formatTime(r.getMillis(), sbuf);
sbuf.append("\t");
sbuf.append(hostname).append("\t").append(processID).append("/").append(r.getThreadID()).append("\t").append(serviceName).append("\t");
if (component == null && componentPrefix == null) {
sbuf.append("-");
} else if (component == null) {
sbuf.append(componentPrefix);
} else if (componentPrefix == null) {
sbuf.append(".").append(component);
} else {
sbuf.append(componentPrefix).append(".").append(component);
}
sbuf.append("\t").append(levelName).append("\t");
// instead we render a string represantion of the event object:
if (r.getLevel() == LogLevel.EVENT) {
Event event = (Event) r.getParameters()[0];
sbuf.append(VespaFormat.escape(event.toString()));
} else {
// otherwise, run standard java text formatting on the message
sbuf.append(VespaFormat.escape(formatMessage(r)));
}
appendException(r.getThrown(), sbuf);
sbuf.append("\n");
return sbuf.toString();
}
use of com.yahoo.log.event.Event in project vespa by vespa-engine.
the class EventTestCase method testFullParse.
public void testFullParse() {
try {
Event event = Event.parse("count/1 name=\"data_searched_mb\" value=15115168.3940149993");
assertTrue(event instanceof Count);
assertEquals("data_searched_mb", event.getValue("name"));
assertEquals("15115168", event.getValue("value"));
} catch (MalformedEventException e) {
fail("Malformed Event Exception on parsing");
}
}
use of com.yahoo.log.event.Event in project vespa by vespa-engine.
the class EventTestCase method testUnknownEvents.
public void testUnknownEvents() throws MalformedEventException {
String s = "crappyevent/2 first=\"value one\" second=more third=4";
Event event = Event.parse(s);
assertEquals(s, event.toString());
String s2 = "notinventedhere/999";
assertEquals(s2, Event.parse(s2).toString());
}
Aggregations