Search in sources :

Example 11 with LogMessage

use of com.yahoo.log.LogMessage 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 12 with LogMessage

use of com.yahoo.log.LogMessage 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 13 with LogMessage

use of com.yahoo.log.LogMessage 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)

Example 14 with LogMessage

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

the class NoMetricsFilterTestCase method testValueEvents.

@Test
public void testValueEvents() throws InvalidLogFormatException, IOException {
    NoMetricsFilter filter = new NoMetricsFilter();
    MetricsFilter metricsFilter = 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)) {
            fail();
        } else {
            assertTrue(true);
        }
        if (metricsFilter.isLoggable(m)) {
            assertTrue(true);
        } else {
            fail();
        }
    }
}
Also used : NoMetricsFilter(com.yahoo.logserver.filter.NoMetricsFilter) LogMessage(com.yahoo.log.LogMessage) MalformedEventException(com.yahoo.log.event.MalformedEventException) BufferedReader(java.io.BufferedReader) Event(com.yahoo.log.event.Event) FileReader(java.io.FileReader) MetricsFilter(com.yahoo.logserver.filter.MetricsFilter) NoMetricsFilter(com.yahoo.logserver.filter.NoMetricsFilter)

Example 15 with LogMessage

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

the class NullFormatterTestCase method testNullFormatter.

@Test
public void testNullFormatter() {
    NullFormatter nf = new NullFormatter();
    LogMessage[] ms = MockLogEntries.getMessages();
    for (LogMessage m : ms) {
        assertEquals(m.toString(), nf.format(m));
    }
}
Also used : NullFormatter(com.yahoo.logserver.formatter.NullFormatter) LogMessage(com.yahoo.log.LogMessage)

Aggregations

LogMessage (com.yahoo.log.LogMessage)19 InvalidLogFormatException (com.yahoo.log.InvalidLogFormatException)5 BufferedReader (java.io.BufferedReader)5 MalformedEventException (com.yahoo.log.event.MalformedEventException)4 FileReader (java.io.FileReader)4 Test (org.junit.Test)4 Event (com.yahoo.log.event.Event)3 MetricsFilter (com.yahoo.logserver.filter.MetricsFilter)2 TextFormatter (com.yahoo.logserver.formatter.TextFormatter)2 LogMetricsHandler (com.yahoo.logserver.handlers.logmetrics.LogMetricsHandler)2 LogDispatcherTestCase (com.yahoo.logserver.test.LogDispatcherTestCase)2 File (java.io.File)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LogDispatcher (com.yahoo.logserver.LogDispatcher)1 LogFilter (com.yahoo.logserver.filter.LogFilter)1 NoMetricsFilter (com.yahoo.logserver.filter.NoMetricsFilter)1 LogFormatter (com.yahoo.logserver.formatter.LogFormatter)1 NullFormatter (com.yahoo.logserver.formatter.NullFormatter)1 AbstractLogHandler (com.yahoo.logserver.handlers.AbstractLogHandler)1