Skip to content

do not log stack trace for CacheException reporting disabled cache an… #4597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,10 @@ private static SourceSplitter trySplitSource(String filename) {
StreamSource src = StreamSource.fromFile(new File(filename));
splitter.reset(src);
} catch (NullPointerException | IOException ex) {
LOGGER.log(Level.WARNING, "Failed to re-read {0}", filename);
LOGGER.log(Level.WARNING, "Failed to re-read ''{0}''", filename);
return null;
}
LOGGER.log(Level.FINEST, "Re-read {0}", filename);
LOGGER.log(Level.FINEST, "Re-read ''{0}''", filename);
return splitter;
}
}
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 @@ -48,8 +49,20 @@ public CacheException(String msg) {
* @param level suggested log level
*/
public CacheException(String msg, Level level) {
this(msg, level, 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 +73,7 @@ public CacheException(String msg, Level level) {
public CacheException(Throwable cause) {
super(cause);
this.level = Level.WARNING;
this.logTrace = true;
}

/**
Expand All @@ -71,6 +85,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 +94,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 @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -239,7 +239,6 @@ public static void writeTagsTo(File outputFile, History history) throws IOExcept
smileFactory.configure(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES, false);

ObjectMapper mapper = new SmileMapper(smileFactory);
// ObjectMapper mapper = new JsonMapper();
ObjectWriter objectWriter = mapper.writer().forType(HashMap.class);

try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
Expand All @@ -255,7 +254,6 @@ private static ObjectWriter getObjectWriter() {
smileFactory.configure(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES, false);

ObjectMapper mapper = new SmileMapper(smileFactory);
// ObjectMapper mapper = new JsonMapper();
return mapper.writer().forType(HistoryEntry.class);
}

Expand Down Expand Up @@ -715,6 +713,7 @@ private void storeLatestCachedRevision(Repository repository, String rev) {
Path newPath = Path.of(getRepositoryCachedRevPath(repository));
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newPath.toFile())))) {
writer.write(rev);
LOGGER.finest(() -> String.format("stored latest cached revision %s for repository %s", rev, repository));
} catch (IOException ex) {
LOGGER.log(Level.WARNING,
String.format("Cannot write latest cached revision to file for repository %s", repository), ex);
Expand Down
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,12 @@ 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);
final String logPrefix = "failed to create annotation";
if (e.isLogTrace()) {
LOGGER.log(e.getLevel(), logPrefix, e);
} else {
LOGGER.log(e.getLevel(), String.format("%s: %s", logPrefix, e.getMessage()));
}
}
}
}
Expand Down
Loading