com.intellij.openapi.diagnostic.IdeaLoggingEvent Java Examples

The following examples show how to use com.intellij.openapi.diagnostic.IdeaLoggingEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogMessage.java    From consulo with Apache License 2.0 6 votes vote down vote up
public LogMessage(IdeaLoggingEvent aEvent) {
  super();

  myThrowable = aEvent.getThrowable();

  if (StringUtil.isNotEmpty(aEvent.getMessage())) {
    myHeader = aEvent.getMessage();
  }

  if (myThrowable != null && StringUtil.isNotEmpty(myThrowable.getMessage())) {
    if (!myHeader.equals(NO_MESSAGE)) {
      if (!myHeader.endsWith(": ") && !myHeader.endsWith(":")) {
        myHeader += ": ";
      }
      myHeader += myThrowable.getMessage();
    }
    else {
      myHeader = myThrowable.getMessage();
    }
  }
}
 
Example #2
Source File: RollbarErrorReportSubmitter.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
private void log(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo) {
  IdeaLoggingEvent ideaEvent = events[0];
  if (ideaEvent.getThrowable() == null) {
    return;
  }
  LinkedHashMap<String, Object> customData = new LinkedHashMap<>();
  customData.put(TAG_PLATFORM_VERSION, ApplicationInfo.getInstance().getBuild().asString());
  customData.put(TAG_OS, SystemInfo.OS_NAME);
  customData.put(TAG_OS_VERSION, SystemInfo.OS_VERSION);
  customData.put(TAG_OS_ARCH, SystemInfo.OS_ARCH);
  customData.put(TAG_JAVA_VERSION, SystemInfo.JAVA_VERSION);
  customData.put(TAG_JAVA_RUNTIME_VERSION, SystemInfo.JAVA_RUNTIME_VERSION);
  if (additionalInfo != null) {
    customData.put(EXTRA_ADDITIONAL_INFO, additionalInfo);
  }
  if (events.length > 1) {
    customData.put(EXTRA_MORE_EVENTS,
        Stream.of(events).map(Object::toString).collect(Collectors.joining("\n")));
  }
  rollbar.codeVersion(getPluginVersion()).log(ideaEvent.getThrowable(), customData);
}
 
Example #3
Source File: DefaultIdeaErrorLogger.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void handle(IdeaLoggingEvent event) {
  if (ourLoggerBroken) return;

  try {
    Throwable throwable = event.getThrowable();
    final MemoryKind kind = getOOMErrorKind(throwable);
    if (kind != null) {
      ourOomOccurred = true;
      SwingUtilities.invokeAndWait(() -> new OutOfMemoryDialog(kind).show());
    }
    else if (throwable instanceof MappingFailedException) {
      processMappingFailed(event);
    }
    else if (!ourOomOccurred) {
      MessagePool messagePool = MessagePool.getInstance();
      messagePool.addIdeFatalMessage(event);
    }
  }
  catch (Throwable e) {
    String message = e.getMessage();
    //noinspection InstanceofCatchParameter
    if (message != null && message.contains("Could not initialize class com.intellij.diagnostic.MessagePool") || e instanceof NullPointerException && ApplicationManager.getApplication() == null) {
      ourLoggerBroken = true;
    }
  }
}
 
Example #4
Source File: Log4J2DialogAppender.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static IdeaLoggingEvent extractLoggingEvent(@Nonnull Message message, @Nonnull Throwable throwable) {
  //noinspection ThrowableResultOfMethodCallIgnored
  Throwable rootCause = ExceptionUtil.getRootCause(throwable);
  if (rootCause instanceof LogEventException) {
    return ((LogEventException)rootCause).getLogMessage();
  }

  String strMessage = message.getFormattedMessage();
  ExceptionWithAttachments withAttachments = ExceptionUtil.findCause(throwable, ExceptionWithAttachments.class);
  if (withAttachments != null) {
    return LogMessageEx.createEvent(strMessage, ExceptionUtil.getThrowableText(throwable), withAttachments.getAttachments());
  }

  return new IdeaLoggingEvent(strMessage, throwable);
}
 
Example #5
Source File: Log4J2DialogAppender.java    From consulo with Apache License 2.0 6 votes vote down vote up
void appendToLoggers(@Nonnull IdeaLoggingEvent ideaEvent) {
  if (myDialogRunnable != null) {
    return;
  }

  final DefaultIdeaErrorLogger logger = DefaultIdeaErrorLogger.INSTANCE;
  if (!logger.canHandle(ideaEvent)) {
    return;
  }
  myDialogRunnable = () -> {
    try {
      logger.handle(ideaEvent);
    }
    finally {
      myDialogRunnable = null;
    }
  };

  final Application app = ApplicationManager.getApplication();
  if (app == null) {
    new Thread(myDialogRunnable).start();
  }
  else {
    app.executeOnPooledThread(myDialogRunnable);
  }
}
 
Example #6
Source File: IdeErrorsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private IdeaLoggingEvent[] getEvents(final AbstractMessage logMessage) {
  if (logMessage instanceof GroupedLogMessage) {
    final List<AbstractMessage> messages = ((GroupedLogMessage)logMessage).getMessages();
    IdeaLoggingEvent[] res = new IdeaLoggingEvent[messages.size()];
    for (int i = 0; i < res.length; i++) {
      res[i] = getEvent(messages.get(i));
    }
    return res;
  }
  return new IdeaLoggingEvent[]{getEvent(logMessage)};
}
 
Example #7
Source File: ITNReporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @noinspection ThrowablePrintStackTrace
 */
private static boolean sendError(IdeaLoggingEvent event,
                                 String additionalInfo,
                                 final Component parentComponent,
                                 final Consumer<SubmittedReportInfo> callback) {
  ErrorReportBean errorBean = new ErrorReportBean(event.getThrowable(), LastActionTracker.ourLastActionId);

  return doSubmit(event, parentComponent, callback, errorBean, additionalInfo);
}
 
Example #8
Source File: LogMessageEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param aEvent
 * @param title            text to show in Event Log tool window entry (it comes before 'more')
 * @param notificationText text to show in the error balloon that is popped up automatically
 */
public LogMessageEx(IdeaLoggingEvent aEvent, String title, String notificationText) {
  super(aEvent);
  myEvent = aEvent;
  myTitle = title;
  myNotificationText = notificationText;
}
 
Example #9
Source File: DefaultIdeaErrorLogger.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processMappingFailed(IdeaLoggingEvent event) throws InterruptedException, InvocationTargetException {
  if (!ourMappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) {
    ourMappingFailedNotificationPosted = true;
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored") String exceptionMessage = event.getThrowable().getMessage();
    String text = exceptionMessage + "<br>Possible cause: unable to allocate continuous memory chunk of necessary size.<br>" + "Reducing JVM maximum heap size (-Xmx) may help.";
    Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), null);
  }
}
 
Example #10
Source File: IdeErrorsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private IdeaLoggingEvent getEvent(final AbstractMessage logMessage) {
  if (logMessage instanceof LogMessageEx) {
    return ((LogMessageEx)logMessage).toEvent();
  }
  return new IdeaLoggingEvent(logMessage.getMessage(), logMessage.getThrowable()) {
    @Override
    public AbstractMessage getData() {
      return logMessage;
    }
  };
}
 
Example #11
Source File: MessagePool.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public LogMessage addIdeFatalMessage(final IdeaLoggingEvent aEvent) {
  Object data = aEvent.getData();
  final LogMessage message = data instanceof LogMessage ? (LogMessage)data : new LogMessage(aEvent);
  if (myIdeFatals.size() < MAX_POOL_SIZE_FOR_FATALS) {
    if (myFatalsGrouper.addToGroup(message)) {
      return message;
    }
  } else if (myIdeFatals.size() == MAX_POOL_SIZE_FOR_FATALS) {
    LogMessage tooMany = new LogMessage(DiagnosticBundle.message("error.monitor.too.many.errors"), new TooManyErrorsException());
    myFatalsGrouper.addToGroup(tooMany);
    return tooMany;
  }
  return null;
}
 
Example #12
Source File: Log4J2Logger.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void error(Object message) {
  if (message instanceof IdeaLoggingEvent) {
    myLogger.error(message);
  }
  else {
    error(String.valueOf(message));
  }
}
 
Example #13
Source File: LogMessageEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param userMessage      user-friendly message description (short, single line if possible)
 * @param details          technical details (exception stack trace etc.)
 * @param title            text to show in Event Log tool window entry (it comes before 'more'), use <code>null</code> to reuse <code>userMessage</code>
 * @param notificationText text to show in the error balloon that is popped up automatically. Default is <code>com.intellij.diagnostic.IdeMessagePanel#INTERNAL_ERROR_NOTICE</code>
 * @param attachment       attachment that will be suggested to include to the report
 * @return
 */
public static IdeaLoggingEvent createEvent(String userMessage,
                                           final String details,
                                           @Nullable final String title,
                                           @Nullable final String notificationText,
                                           @Nullable Attachment attachment) {
  return createEvent(userMessage, details, title, notificationText,
                     attachment != null ? Collections.singletonList(attachment) : Collections.<Attachment>emptyList());
}
 
Example #14
Source File: SentryBugReporter.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private StringBuilder getMoreEvents(@NotNull IdeaLoggingEvent[] events) {
    StringBuilder moreEvents = new StringBuilder();
    for (int i = 1; i < events.length; i++) {
        IdeaLoggingEvent event = events[i];
        moreEvents.append(event.toString());
        moreEvents.append("\n");
    }
    return moreEvents;
}
 
Example #15
Source File: SentryBugReporter.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private EventBuilder createEvent(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo) {
    IdeaLoggingEvent ideaEvent = events[0];
    EventBuilder eventBuilder = new EventBuilder();
    eventBuilder.withMessage(ideaEvent.getMessage());
    eventBuilder.withRelease(getPluginVersion());
    eventBuilder.withTag(TAG_PLATFORM_VERSION, getPlatformVersion());
    eventBuilder.withTag(TAG_OS, SystemInfo.OS_NAME);
    eventBuilder.withTag(TAG_OS_VERSION, SystemInfo.OS_VERSION);
    eventBuilder.withTag(TAG_OS_ARCH, SystemInfo.OS_ARCH);
    eventBuilder.withTag(TAG_JAVA_VERSION, SystemInfo.JAVA_VERSION);
    eventBuilder.withTag(TAG_JAVA_RUNTIME_VERSION, SystemInfo.JAVA_RUNTIME_VERSION);
    Object data = ideaEvent.getData();
    if (data instanceof LogMessage) {
        LogMessage logMessage = (LogMessage) data;
        Throwable throwable = logMessage.getThrowable();
        eventBuilder.withSentryInterface(new ExceptionInterface(throwable));
    } else if (ideaEvent.getThrowable() != null) {
        eventBuilder.withSentryInterface(new ExceptionInterface(ideaEvent.getThrowable()));
    }
    if (additionalInfo != null) {
        eventBuilder.withExtra(EXTRA_ADDITIONAL_INFO, additionalInfo);
    }
    if (events.length > 1) {
        eventBuilder.withExtra(EXTRA_MORE_EVENTS, getMoreEvents(events));
    }
    eventBuilder.withExtra(EXTRA_OTHER_PLUGINS, getOtherPluginsInfo());
    return eventBuilder;
}
 
Example #16
Source File: SentryBugReporter.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo,
                      @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
    EventBuilder eventBuilder = createEvent(events, additionalInfo);
    sentry.sendEvent(eventBuilder);
    consumer.consume(new SubmittedReportInfo(null, null, NEW_ISSUE));
    Messages.showInfoMessage(parentComponent, DEFAULT_RESPONSE, DEFAULT_RESPONSE_TITLE);
    return true;
}
 
Example #17
Source File: RollbarErrorReportSubmitter.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo,
    @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
  log(events, additionalInfo);
  consumer.consume(new SubmittedReportInfo(null, null, NEW_ISSUE));
  Messages.showInfoMessage(parentComponent, DEFAULT_RESPONSE, DEFAULT_RESPONSE_TITLE);
  return true;
}
 
Example #18
Source File: ErrorReportHandler.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
    for (IdeaLoggingEvent event : events) {
        Throwable throwable = event.getThrowable();
        if (event.getData() instanceof AbstractMessage) {
            throwable = ((AbstractMessage) event.getData()).getThrowable();
        }

        SentryUtils.submitErrorReport(throwable, additionalInfo);
    }

    return true;
}
 
Example #19
Source File: ErrorReporter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public SubmittedReportInfo submit(IdeaLoggingEvent[] ideaLoggingEvents, Component component) {
  StringBuilder builder = new StringBuilder();
  for (IdeaLoggingEvent evt : ideaLoggingEvents) builder.append(evt.getMessage());
  final boolean b = reportBug(builder.toString(), component);
  return new SubmittedReportInfo(null, "email", b ? SubmittedReportInfo.SubmissionStatus.NEW_ISSUE: SubmittedReportInfo.SubmissionStatus.FAILED);
}
 
Example #20
Source File: LogEventException.java    From consulo with Apache License 2.0 4 votes vote down vote up
public IdeaLoggingEvent getLogMessage() {
  return myLogMessage;
}
 
Example #21
Source File: LogMessageEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
public IdeaLoggingEvent toEvent() {
  return myEvent;
}
 
Example #22
Source File: GitHubErrorReporter.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, String additionalInfo, @NotNull Component parentComponent,
                      @NotNull Consumer<SubmittedReportInfo> consumer) {
    GitHubErrorBean errorBean = new GitHubErrorBean(events[0].getThrowable(), IdeaLogger.ourLastActionId);
    return doSubmit(events[0], parentComponent, consumer, errorBean, additionalInfo);
}
 
Example #23
Source File: LogEventException.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LogEventException(IdeaLoggingEvent logMessage) {
  super(logMessage.getMessage());
  myLogMessage = logMessage;
}
 
Example #24
Source File: ITNReporter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean trySubmitAsync(IdeaLoggingEvent[] events, String additionalInfo, Component parentComponent, Consumer<SubmittedReportInfo> consumer) {
  return sendError(events[0], additionalInfo, parentComponent, consumer);
}
 
Example #25
Source File: DefaultIdeaErrorLogger.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean canHandle(IdeaLoggingEvent event) {
  return !ourLoggerBroken;
}
 
Example #26
Source File: PluginErrorReportSubmitter.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull final Component parentComponent, @NotNull final Consumer<SubmittedReportInfo> consumer) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    StringBuilder stacktrace = new StringBuilder();
    for (IdeaLoggingEvent event : events) {
        stacktrace.append(event.getMessage()).append("\n");
        stacktrace.append(event.getThrowableText()).append("\n");
    }

    Properties properties = new Properties();
    queryPluginDescriptor(getPluginDescriptor(), properties);

    StringBuilder versionId = new StringBuilder();
    versionId.append(properties.getProperty(PLUGIN_ID_PROPERTY_KEY)).append(" ").append(properties.getProperty(PLUGIN_VERSION_PROPERTY_KEY));
    versionId.append(", ").append(ApplicationInfo.getInstance().getBuild().asString());

    // show modal error submission dialog
    PluginErrorSubmitDialog dialog = new PluginErrorSubmitDialog(parentComponent);
    dialog.prepare(additionalInfo, stacktrace.toString(), versionId.toString());
    dialog.show();

    // submit error to server if user pressed SEND
    int code = dialog.getExitCode();
    if (code == DialogWrapper.OK_EXIT_CODE) {
        dialog.persist();

        String description = dialog.getDescription();
        String user = dialog.getUser();
        String editedStacktrace = dialog.getStackTrace();

        submitToServer(project, editedStacktrace, description, user,
                new Consumer<SubmittedReportInfo>() {
                    @Override
                    public void consume(SubmittedReportInfo submittedReportInfo) {
                        consumer.consume(submittedReportInfo);

                        ApplicationManager.getApplication().invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                Messages.showInfoMessage(parentComponent, "The error report has been submitted successfully. Thank you for your feedback!", "BashSupport Error Submission");
                            }
                        });
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void consume(Throwable throwable) {
                        LOGGER.info("Error submission failed", throwable);
                        consumer.consume(new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.FAILED));
                    }
                }
        );

        return true;
    }

    return false;
}
 
Example #27
Source File: GitHubErrorReporter.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
@SuppressWarnings("BooleanMethodNameMustStartWithQuestion")
private static boolean doSubmit(final IdeaLoggingEvent event,
                                final Component parentComponent,
                                final Consumer<SubmittedReportInfo> callback,
                                final GitHubErrorBean bean,
                                final String description) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);

    bean.setDescription(description);
    bean.setMessage(event.getMessage());

    if (event instanceof IdeaReportingEvent) {
        IdeaReportingEvent reportingEvent = (IdeaReportingEvent) event;
        IdeaPluginDescriptor descriptor = reportingEvent.getPlugin();
        if (descriptor != null) {
            bean.setPluginName(descriptor.getName());
            bean.setPluginVersion(descriptor.getVersion());
        }
    }

    Object data = event.getData();

    if (data instanceof LogMessage) {
        bean.setAttachments(((LogMessage) data).getIncludedAttachments());
    }

    ErrorReportInformation errorReportInformation = ErrorReportInformation
            .getUsersInformation(bean,
                    (ApplicationInfoEx) ApplicationInfo.getInstance(),
                    ApplicationNamesInfo.getInstance());

    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    final CallbackWithNotification notifyingCallback = new CallbackWithNotification(callback, project);
    AnonymousFeedbackTask task =
            new AnonymousFeedbackTask(project,
                    IntelliJDeodorantBundle.message("report.error.progress.dialog.text"),
                    true,
                    errorReportInformation,
                    notifyingCallback);
    if (project == null) {
        task.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(task);
    }
    return true;
}
 
Example #28
Source File: LogMessageEx.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @param userMessage      user-friendly message description (short, single line if possible)
 * @param details          technical details (exception stack trace etc.)
 * @param attachments      attachments that will be suggested to include to the report
 * @return
 */
public static IdeaLoggingEvent createEvent(String userMessage, final String details, final Attachment... attachments) {
  return createEvent(userMessage, details, userMessage, null, Arrays.asList(attachments));
}