Search in sources :

Example 1 with LogCatMessage

use of com.android.ddmlib.logcat.LogCatMessage in project android by JetBrains.

the class AndroidLogFilterModel method processLine.

@Override
@NotNull
public final MyProcessingResult processLine(String line) {
    LogCatMessage message = AndroidLogcatFormatter.tryParseMessage(line);
    String continuation = (message == null) ? AndroidLogcatFormatter.tryParseContinuation(line) : null;
    boolean validContinuation = continuation != null && myPrevHeader != null;
    if (message == null && !validContinuation) {
        return new MyProcessingResult(ProcessOutputTypes.STDOUT, false, null);
    }
    if (message != null) {
        myPrevHeader = message.getHeader();
        myCustomApplicable = isApplicable(line);
        myConfiguredApplicable = isApplicableByConfiguredFilter(message.getMessage());
        myMessageSoFar.setLength(0);
    } else {
        myCustomApplicable = myCustomApplicable || isApplicable(continuation);
        myConfiguredApplicable = myConfiguredApplicable || isApplicableByConfiguredFilter(continuation);
    }
    boolean isApplicable = myCustomApplicable && myConfiguredApplicable;
    if (isApplicable && myRejectBeforeTime != null) {
        isApplicable = !myPrevHeader.getTimestamp().isBefore(myRejectBeforeTime);
    }
    if (!isApplicable) {
        // Even if this message isn't applicable right now, store it in case it becomes so later
        myMessageSoFar.append(line);
        myMessageSoFar.append('\n');
    }
    Key key = AndroidLogcatUtils.getProcessOutputType(myPrevHeader.getLogLevel());
    MyProcessingResult result = new MyProcessingResult(key, isApplicable, myMessageSoFar.toString());
    if (isApplicable) {
        // Don't need anymore, already added as a prefix at this point
        myMessageSoFar.setLength(0);
    }
    return result;
}
Also used : LogCatMessage(com.android.ddmlib.logcat.LogCatMessage) Key(com.intellij.openapi.util.Key) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LogCatMessage

use of com.android.ddmlib.logcat.LogCatMessage in project android by JetBrains.

the class AndroidLogcatFormatter method formatMessage.

@Override
public String formatMessage(String msg) {
    String continuation = tryParseContinuation(msg);
    if (continuation != null) {
        return Strings.repeat(" ", myLastHeaderLength) + continuation;
    } else {
        LogCatMessage message = tryParseMessage(msg);
        if (message != null) {
            String formatted = formatMessage(myPreferences.LOGCAT_FORMAT_STRING, msg);
            myLastHeaderLength = formatted.indexOf(message.getMessage());
            return formatted;
        }
    }
    // Unknown message format, return as is
    return msg;
}
Also used : LogCatMessage(com.android.ddmlib.logcat.LogCatMessage)

Example 3 with LogCatMessage

use of com.android.ddmlib.logcat.LogCatMessage in project android by JetBrains.

the class AndroidLogcatFormatter method tryParseMessage.

/**
   * Returns the result of {@link #parseMessage(String)} or {@code null} if the format of the input
   * text doesn't match.
   */
@Nullable
public static LogCatMessage tryParseMessage(@NotNull String msg) {
    final Matcher matcher = MESSAGE_WITH_HEADER.matcher(msg);
    if (!matcher.matches()) {
        return null;
    }
    // matcher.matches verifies all groups below are non-null
    @SuppressWarnings("ConstantConditions") LogCatHeader header = new LogCatHeader(Log.LogLevel.getByLetter(matcher.group(5).charAt(0)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)), matcher.group(4), matcher.group(6), LogCatTimestamp.fromString(matcher.group(1)));
    String message = matcher.group(7);
    return new LogCatMessage(header, message);
}
Also used : Matcher(java.util.regex.Matcher) LogCatHeader(com.android.ddmlib.logcat.LogCatHeader) LogCatMessage(com.android.ddmlib.logcat.LogCatMessage) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LogCatMessage

use of com.android.ddmlib.logcat.LogCatMessage in project android by JetBrains.

the class AndroidLogcatReceiver method notifyLine.

// This method is package protected so other Logcat components can feed receiver processed log lines if they need to
void notifyLine(@NotNull LogCatHeader header, @NotNull String line) {
    myLogcatListener.onLogLineReceived(new LogCatMessage(header, line));
    myLineIndex++;
}
Also used : LogCatMessage(com.android.ddmlib.logcat.LogCatMessage)

Example 5 with LogCatMessage

use of com.android.ddmlib.logcat.LogCatMessage in project android by JetBrains.

the class EditLogFilterDialog method parseExistingMessagesIfNecessary.

private void parseExistingMessagesIfNecessary() {
    if (myExistingMessagesParsed) {
        return;
    }
    myExistingMessagesParsed = true;
    final StringBuffer document = myView.getLogConsole().getOriginalDocument();
    if (document == null) {
        return;
    }
    final Set<String> pidSet = new HashSet<>();
    final String[] lines = StringUtil.splitByLines(document.toString());
    for (String line : lines) {
        LogCatMessage message = AndroidLogcatFormatter.parseMessage(line);
        pidSet.add(Integer.toString(message.getPid()));
    }
    myUsedPids = Lists.newArrayList(pidSet);
}
Also used : LogCatMessage(com.android.ddmlib.logcat.LogCatMessage) HashSet(com.intellij.util.containers.HashSet)

Aggregations

LogCatMessage (com.android.ddmlib.logcat.LogCatMessage)6 LogCatHeader (com.android.ddmlib.logcat.LogCatHeader)2 Key (com.intellij.openapi.util.Key)1 HashSet (com.intellij.util.containers.HashSet)1 Matcher (java.util.regex.Matcher)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.Test)1