Search in sources :

Example 6 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class LogReaderTest method testSuperLongLogNoFilterSVCParser.

/**
 * Test if readMessage() can read super long service log from file and parse it correctly
 */
@Test
public void testSuperLongLogNoFilterSVCParser() throws Exception {
    LogStatusInfo status = new LogStatusInfo();
    LogRequest req = new LogRequest.Builder().build();
    LogReader reader = new LogReader(superLongSvcLogPath, req, status, null);
    LogMessage l = reader.readNextLogMessage();
    Calendar calendar = Calendar.getInstance();
    // month starts from 0;
    calendar.set(2014, 0, 16, 19, 00, 1);
    calendar.set(Calendar.MILLISECOND, 519);
    Date date = calendar.getTime();
    long time = date.getTime();
    assertEquals("Time is wrong", l.getTime(), time);
    assertTrue("Thread name is wrong", Arrays.equals(LogUtil.stringToBytes("pool-35-thread-1"), l.getThreadName()));
    assertEquals("Log level is wrong", new String(l.getLevel()), "INFO");
    assertTrue("File name is wrong", Arrays.equals(LogUtil.stringToBytes("DefaultSingletonBeanRegistry"), l.getFileName()));
    assertTrue("Line number is wrong", Arrays.equals(l.getLineNumber(), LogUtil.stringToBytes("433")));
    assertTrue("Log message contact is wrong", Arrays.equals(LogUtil.stringToBytes("Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@25f13769: defining beans [namespaces,scanner,registeredProfiles,reference-profile,profile-prop,profileProcessor,providerVersionSupport,resultClass-softwareIdentity,softwareIdentity-prop,softwareIdentityProcessor,system,resultClass-system,system-prop,scannerProcessor,model,reference-comp,resultClass-chassis,model-prop,modelProcessor,argscreator,smiutility,cimClient,block,commandgenerator,executor,null,bool,bool-true]; root of factory hierarchy"), l.getLogContent()));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Example 7 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class ParserTest method testNginxAccessLog.

@Test
public void testNginxAccessLog() throws Exception {
    LogReader reader = null;
    String regexStr = ".*login HTTP.*";
    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_access.log";
    String filePath = nginxAccessLogPath;
    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 null", new String(log.getLevel()).equals("null"));
    assertTrue("log line is not -1", new String(log.getLineNumber()).equals("-1"));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Example 8 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class ParserTest method testParticularLog.

@Test
public void testParticularLog() throws Exception {
    LogReader reader = null;
    LogRequest request = new LogRequest.Builder().build();
    LogStatusInfo status = new LogStatusInfo();
    String filePath = particularLogPath;
    String baseName = "log";
    reader = new LogReader(filePath, request, status, baseName);
    final LogMessage log = reader.readNextLogMessage();
    assertTrue("log is null", log != null);
    // assertTrue("log message is null", log.getLogContent() != null);
    assertTrue("log message is null", log.getLogContent() != null);
    assertTrue("log file name is null", log.getFileName() != null);
    assertTrue("log thread name is null", log.getThreadName() != null);
    assertTrue("log level is not Error", new String(log.getLevel()).equals("ERROR"));
    assertTrue("log line is null", log.getLineNumber() != null);
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Test(org.junit.Test)

Example 9 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader 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"));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Example 10 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader 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");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Aggregations

LogReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogReader)10 LogRequest (com.emc.vipr.model.sys.logging.LogRequest)10 Test (org.junit.Test)10 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)7 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)7 Calendar (java.util.Calendar)5 Date (java.util.Date)5 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 File (java.io.File)1