Java Code Examples for com.intellij.openapi.diagnostic.Logger#getInstance()

The following examples show how to use com.intellij.openapi.diagnostic.Logger#getInstance() . 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: Util.java    From sourcegraph-jetbrains with Apache License 2.0 6 votes vote down vote up
public static String exec(String cmd, String dir) throws IOException {
    Logger.getInstance(Util.class).debug("exec cmd='" + cmd + "' dir="+dir);

    // Create the process.
    Process p = Runtime.getRuntime().exec(cmd, null, new File(dir));
    BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    // Log any stderr ouput.
    Logger logger = Logger.getInstance(Util.class);
    String s;
    while ((s = stderr.readLine()) != null) {
        logger.debug(s);
    }

    String out = new String();
    for (String l; (l = stdout.readLine()) != null; out += l + "\n");
    return out;
}
 
Example 2
Source File: GradleBuildModel.java    From ok-gradle with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the given supplier and returns the result if no exception was thrown. If an exception was thrown then
 * log it to back intellijs logs and the AndroidStudioCrashReporter and return null.
 *
 * @param supplier supplier to run
 * @return supplied value or null if an exception was thrown
 */
@Nullable
static <T> T tryOrLog(@NotNull Supplier<T> supplier) {
  try {
    return supplier.get();
  } catch (Exception e) {
    if (e instanceof ControlFlowException) {
      // Control-Flow exceptions should not be logged and reported.
      return null;
    }
    Logger logger = Logger.getInstance(ProjectBuildModel.class);
    logger.error(e);

    // TODO: this would be a place to report crash
    // Since this would have caused an IDE crash we still want to report any exceptions for monitoring.
    // StudioCrashReporter reporter = StudioCrashReporter.getInstance();
    // reporter.submit(new StudioExceptionReport.Builder().setThrowable(e, false).build());
    return null;
  }
}
 
Example 3
Source File: Open.java    From sourcegraph-jetbrains with Apache License 2.0 5 votes vote down vote up
@Override
void handleFileUri(String uri) {
    Logger logger = Logger.getInstance(this.getClass());
    // Open the URL in the browser.
    try {
        Desktop.getDesktop().browse(URI.create(uri));
    } catch (IOException err) {
        logger.debug("failed to open browser");
        err.printStackTrace();
    }
    return;
}
 
Example 4
Source File: Log.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
private Log(String name) {
    m_log = Logger.getInstance("ReasonML." + name);
}
 
Example 5
Source File: DuneOutputListener.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
public DuneOutputListener(@NotNull Project project, CompilerProcess compilerLifecycle) {
    m_project = project;
    m_compilerLifecycle = compilerLifecycle;
    m_log = Logger.getInstance("ReasonML.build");
}
 
Example 6
Source File: FileAction.java    From sourcegraph-jetbrains with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Logger logger = Logger.getInstance(this.getClass());

    // Get project, editor, document, file, and position information.
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    Document currentDoc = editor.getDocument();
    if (currentDoc == null) {
        return;
    }
    VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc);
    if (currentFile == null) {
        return;
    }
    SelectionModel sel = editor.getSelectionModel();

    // Get repo information.
    RepoInfo repoInfo = Util.repoInfo(currentFile.getPath());
    if (repoInfo.remoteURL == "") {
        return;
    }

    // Build the URL that we will open.
    String productName = ApplicationInfo.getInstance().getVersionName();
    String productVersion = ApplicationInfo.getInstance().getFullVersion();
    String uri;
    try {
        LogicalPosition start = editor.visualToLogicalPosition(sel.getSelectionStartPosition());
        LogicalPosition end = editor.visualToLogicalPosition(sel.getSelectionEndPosition());
        uri = Util.sourcegraphURL(project)+"-/editor"
                + "?remote_url=" + URLEncoder.encode(repoInfo.remoteURL, "UTF-8")
                + "&branch=" + URLEncoder.encode(repoInfo.branch, "UTF-8")
                + "&file=" + URLEncoder.encode(repoInfo.fileRel, "UTF-8")
                + "&editor=" + URLEncoder.encode("JetBrains", "UTF-8")
                + "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8")
                + "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8")
                + "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8")
                + "&start_row=" + URLEncoder.encode(Integer.toString(start.line), "UTF-8")
                + "&start_col=" + URLEncoder.encode(Integer.toString(start.column), "UTF-8")
                + "&end_row=" + URLEncoder.encode(Integer.toString(end.line), "UTF-8")
                + "&end_col=" + URLEncoder.encode(Integer.toString(end.column), "UTF-8");
    } catch (UnsupportedEncodingException err) {
        logger.debug("failed to build URL");
        err.printStackTrace();
        return;
    }

    handleFileUri(uri);
}
 
Example 7
Source File: CodeMakerUtil.java    From CodeMaker with Apache License 2.0 4 votes vote down vote up
public static Logger getLogger(Class clazz) {
    return Logger.getInstance(clazz);
}
 
Example 8
Source File: ProjectWrangler.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
private Logger getLogger() {
  return Logger.getInstance(getClass());
}
 
Example 9
Source File: HaxeDebugTimeLog.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public HaxeDebugTimeLog(@Nullable String messagePrefix, Since since) {
  this(Logger.getInstance(messagePrefix), since);
  myLog.setLevel(Level.DEBUG);
}