Skip to content

Commit

Permalink
do not log stack trace for CacheException reporting disabled cache an…
Browse files Browse the repository at this point in the history
…notation

fixes oracle#4596
  • Loading branch information
vladak committed Jul 15, 2024
1 parent fd87436 commit 9c72bc5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.history;

Expand All @@ -32,6 +32,7 @@ public class CacheException extends Exception {
private static final long serialVersionUID = 1L;

private final Level level;
private final boolean logTrace;

/**
* Construct a {@code CacheException} with the specified message.
Expand All @@ -50,6 +51,20 @@ public CacheException(String msg) {
public CacheException(String msg, Level level) {
super(msg);
this.level = level;
this.logTrace = true;
}

/**
* Construct a {@code CacheException} with the specified message and log level
* and whether to log stack trace.
* @param msg message
* @param level suggested log level
* @param logTrace whether to log stack trace
*/
public CacheException(String msg, Level level, boolean logTrace) {
super(msg);
this.level = level;
this.logTrace = logTrace;
}

/**
Expand All @@ -60,6 +75,7 @@ public CacheException(String msg, Level level) {
public CacheException(Throwable cause) {
super(cause);
this.level = Level.WARNING;
this.logTrace = true;
}

/**
Expand All @@ -71,6 +87,7 @@ public CacheException(Throwable cause) {
public CacheException(String msg, Throwable cause) {
super(msg, cause);
this.level = Level.WARNING;
this.logTrace = true;
}

/**
Expand All @@ -79,4 +96,8 @@ public CacheException(String msg, Throwable cause) {
public Level getLevel() {
return level;
}

public boolean isLogTrace() {
return this.logTrace;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ public void createAnnotationCache(File file, String latestRev) throws CacheExcep
if (!repository.isWorking() || !repository.isAnnotationCacheEnabled()) {
throw new CacheException(
String.format("repository %s does not allow to create annotation cache for '%s'",
repository, file), Level.FINER);
repository, file), Level.FINER, false);
}

LOGGER.finest(() -> String.format("creating annotation cache for '%s'", launderLog(file.toString())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ private static void createAnnotationCache(File file, Document doc) {
// call above) directly.
HistoryGuru.getInstance().createAnnotationCache(file, lastRev);
} catch (CacheException e) {
LOGGER.log(e.getLevel(), "failed to create annotation", e);
LOGGER.log(e.getLevel(), "failed to create annotation", e.isLogTrace() ? e : e.getMessage());
}
}
}
Expand Down

0 comments on commit 9c72bc5

Please sign in to comment.