Search in sources :

Example 1 with InvalidLogFormatException

use of com.yahoo.log.InvalidLogFormatException 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();
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException) MalformedEventException(com.yahoo.log.event.MalformedEventException) BufferedReader(java.io.BufferedReader) Event(com.yahoo.log.event.Event) FileInputStream(java.io.FileInputStream)

Example 2 with InvalidLogFormatException

use of com.yahoo.log.InvalidLogFormatException in project vespa by vespa-engine.

the class ArchiverHandlerTestCase method testFilenameCreation.

/**
 * Test that the ArchiverHandler creates correct filenames.
 */
@Test
public void testFilenameCreation() throws IOException {
    File tmpDir = temporaryFolder.newFolder();
    try {
        ArchiverHandler a = new ArchiverHandler(tmpDir.getAbsolutePath(), 1024);
        LogMessage msg1 = LogMessage.parseNativeFormat("1139322725\thost\tthread\tservice\tcomponent\tinfo\tpayload");
        LogMessage msg2 = LogMessage.parseNativeFormat("1161172200\thost\tthread\tservice\tcomponent\tinfo\tpayload");
        assertEquals(tmpDir.getAbsolutePath() + "/2006/02/07/14", a.getPrefix(msg1));
        assertEquals(tmpDir.getAbsolutePath() + "/2006/10/18/11", a.getPrefix(msg2));
        assertEquals(a.getPrefix(msg1).length(), a.getPrefix(msg2).length());
        a.close();
    } catch (InvalidLogFormatException e) {
        fail(e.toString());
    } finally {
        IOUtils.recursiveDeleteDir(tmpDir);
    }
}
Also used : LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException) File(java.io.File)

Example 3 with InvalidLogFormatException

use of com.yahoo.log.InvalidLogFormatException in project vespa by vespa-engine.

the class RankSetupValidator method validateFail.

private void validateFail(String output, SearchCluster sc, String sdName, DeployLogger deployLogger) {
    String errMsg = "For search cluster '" + sc.getClusterName() + "', search definition '" + sdName + "': error in rank setup. Details:\n";
    for (String line : output.split("\n")) {
        // Remove debug lines from start script
        if (line.startsWith("debug\t"))
            continue;
        try {
            LogMessage logmsg = LogMessage.parseNativeFormat(line);
            errMsg = errMsg + logmsg.getLevel() + ": " + logmsg.getPayload() + "\n";
        } catch (InvalidLogFormatException e) {
            errMsg = errMsg + line + "\n";
        }
    }
    if (force) {
        deployLogger.log(LogLevel.WARNING, errMsg + "(Continuing because of force.)");
    } else {
        throw new IllegalArgumentException(errMsg);
    }
}
Also used : LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException)

Example 4 with InvalidLogFormatException

use of com.yahoo.log.InvalidLogFormatException in project vespa by vespa-engine.

the class LogConnection method read.

public void read() throws IOException {
    if (!readBuffer.hasRemaining()) {
        try {
            readBuffer.putChar(readBuffer.capacity() - 2, '\n');
            readBuffer.flip();
            String s = ReadLine.readLine(readBuffer);
            if (s == null) {
                return;
            }
            log.log(LogLevel.DEBUG, "Log message too long. Message from " + socket.socket().getInetAddress() + " exceeds " + readBuffer.capacity() + ". The message was: " + s);
            LogMessage msg = LogMessage.parseNativeFormat(s);
            dispatcher.handle(msg);
        } catch (InvalidLogFormatException e) {
            log.log(LogLevel.DEBUG, "Invalid log message", e);
        } finally {
            readBuffer.clear();
        }
        return;
    }
    int ret = socket.read(readBuffer);
    if (ret == -1) {
        close();
        return;
    }
    if (ret == 0) {
        if (log.isLoggable(Level.FINE)) {
            log.log(LogLevel.DEBUG, "zero byte read occurred");
        }
    }
    // update global counter
    totalBytesRead += ret;
    readBuffer.flip();
    String s;
    while ((s = ReadLine.readLine(readBuffer)) != null) {
        try {
            LogMessage msg = LogMessage.parseNativeFormat(s);
            dispatcher.handle(msg);
        } catch (InvalidLogFormatException e) {
            log.log(LogLevel.DEBUG, "Invalid log message", e);
        }
    }
}
Also used : LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException)

Example 5 with InvalidLogFormatException

use of com.yahoo.log.InvalidLogFormatException in project vespa by vespa-engine.

the class VerifyLogfile method main.

public static void main(String[] args) throws IOException {
    int messages = 0;
    int events = 0;
    int invalidLogMessages = 0;
    int invalidEvents = 0;
    int numFiles = 0;
    if (args.length < 1) {
        System.err.println("\nPlease provide name of log file(s)\n");
    }
    for (int i = 0; i < args.length; i++) {
        BufferedReader br = new BufferedReader(new FileReader(args[i]));
        numFiles++;
        for (String line = br.readLine(); line != null; line = br.readLine()) {
            messages++;
            LogMessage m;
            try {
                m = LogMessage.parseNativeFormat(line);
                if (m.getLevel() == LogLevel.EVENT) {
                    events++;
                    m.getEvent();
                }
            } catch (MalformedEventException e) {
                System.out.println("EVENT\t" + line);
                invalidEvents++;
            } catch (InvalidLogFormatException e) {
                System.out.println("MESSAGE\t" + line);
                invalidLogMessages++;
            }
        }
        br.close();
    }
    System.err.println("numFiles: " + numFiles);
    System.err.println("messages: " + messages);
    System.err.println("events: " + events);
    System.err.println("invalidLogMessages: " + invalidLogMessages);
    System.err.println("invalidEvents: " + invalidEvents);
}
Also used : LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException) MalformedEventException(com.yahoo.log.event.MalformedEventException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

InvalidLogFormatException (com.yahoo.log.InvalidLogFormatException)5 LogMessage (com.yahoo.log.LogMessage)5 MalformedEventException (com.yahoo.log.event.MalformedEventException)2 BufferedReader (java.io.BufferedReader)2 Event (com.yahoo.log.event.Event)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 GZIPInputStream (java.util.zip.GZIPInputStream)1