use of com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo in project coprhd-controller by CoprHD.
the class ParserTest method testNginxErrorLog.
@Test
public void testNginxErrorLog() throws Exception {
LogReader reader = null;
String regexStr = ".*server: localhost, request:.*";
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 1, 20, 16, 38, 16);
Date startTimeFilter = calendar.getTime();
calendar.set(2014, 6, 16, 16, 38, 0);
Date endTimeFilter = calendar.getTime();
LogRequest request = new LogRequest.Builder().regex(regexStr).startTime(startTimeFilter).endTime(endTimeFilter).build();
LogStatusInfo status = new LogStatusInfo();
// "/opt/storageos/logs/nginx_error.log";
String filePath = nginxErrorLogPath;
String baseName = "nginx";
reader = new LogReader(filePath, request, status, baseName);
final LogMessage log = reader.readNextLogMessage();
assertTrue("log is null", log != null);
assertTrue("log message is null", !new String(log.getLogContent()).equals("null"));
assertTrue("log message does not match regex", Pattern.compile(regexStr, Pattern.DOTALL | Pattern.MULTILINE).matcher(LogUtil.bytesToString(log.getLogContent())).matches());
assertTrue("log time does not fit time filter", log.getTime() >= startTimeFilter.getTime() && log.getTime() <= endTimeFilter.getTime());
assertTrue("log file name is not null", new String(log.getFileName()).equals("null"));
assertTrue("log thread name not is null", new String(log.getThreadName()).equals("null"));
assertTrue("log level is not Error", new String(log.getLevel()).equalsIgnoreCase("ERROR"));
assertTrue("log line is not -1", new String(log.getLineNumber()).equals("-1"));
}
use of com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo in project coprhd-controller by CoprHD.
the class SysLogReaderTest method testAllLogFormatSmallFileNoFilterSysParser.
/**
* Test if readMessage() can read and parse syssvc file which has different
* format logs correctly
*/
@Test
public void testAllLogFormatSmallFileNoFilterSysParser() throws Exception {
System.out.println("starting testAllLogFormatSmallFileNoFilterSysParser");
LogStatusInfo status = new LogStatusInfo();
String filePath = "src/main/data/testReaderData/testSyslogParser.log";
LogReader reader = null;
LogRequest req = new LogRequest.Builder().build();
reader = new LogReader(filePath, req, status, null);
BufferedReader br = new BufferedReader(new FileReader("src/main/data/testReaderData/testSyslogParser.log"));
while (true) {
LogMessage log = reader.readNextLogMessage();
String line = br.readLine();
if (line == null) {
assertNull("Log should be null", log);
break;
}
assertEquals("whole log message mismatch", log.toStringOriginalFormatSysLog(), line);
}
br.close();
System.out.println("done testAllLogFormatSmallFileNoFilterSysParser");
}
Aggregations