Skip to content

Commit 30bba29

Browse files
idodeclareVladimir Kotal
authored andcommitted
Vary Level for printProgress(). Rem redundant getFileCount().
Also: - Adjust some levels so INFO is less verbose and FINEST fills out.
1 parent 380df9e commit 30bba29

File tree

5 files changed

+59
-56
lines changed

5 files changed

+59
-56
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ public static AbstractAnalyzer getAnalyzer(InputStream in, String file) throws I
497497
AnalyzerFactory factory = find(in, file);
498498
if (factory == null) {
499499
AbstractAnalyzer defaultAnalyzer = getAnalyzer();
500-
if (LOGGER.isLoggable(Level.FINE)) {
501-
LOGGER.log(Level.FINE, "{0}: fallback {1}",
500+
if (LOGGER.isLoggable(Level.FINEST)) {
501+
LOGGER.log(Level.FINEST, "{0}: fallback {1}",
502502
new Object[]{file,
503503
defaultAnalyzer.getClass().getSimpleName() });
504504
}
@@ -878,8 +878,8 @@ public static AnalyzerFactory find(String file) {
878878
if (dotpos > 0) {
879879
factory = pre.get(path.substring(0, dotpos).toUpperCase(Locale.ROOT));
880880
if (factory != null) {
881-
if (LOGGER.isLoggable(Level.FINER)) {
882-
LOGGER.log(Level.FINER, "{0}: chosen by prefix: {1}",
881+
if (LOGGER.isLoggable(Level.FINEST)) {
882+
LOGGER.log(Level.FINEST, "{0}: chosen by prefix: {1}",
883883
new Object[]{file,
884884
factory.getClass().getSimpleName() });
885885
}
@@ -892,8 +892,8 @@ public static AnalyzerFactory find(String file) {
892892
// cases when this does not work.
893893
factory = ext.get(path.substring(dotpos + 1).toUpperCase(Locale.ROOT));
894894
if (factory != null) {
895-
if (LOGGER.isLoggable(Level.FINER)) {
896-
LOGGER.log(Level.FINER, "{0}: chosen by suffix: {1}",
895+
if (LOGGER.isLoggable(Level.FINEST)) {
896+
LOGGER.log(Level.FINEST, "{0}: chosen by suffix: {1}",
897897
new Object[]{file,
898898
factory.getClass().getSimpleName() });
899899
}
@@ -952,8 +952,8 @@ private static AnalyzerFactory findForStream(InputStream in,
952952
if (matcher.getIsPreciseMagic()) {
953953
fac = matcher.isMagic(content, in);
954954
if (fac != null) {
955-
if (LOGGER.isLoggable(Level.FINER)) {
956-
LOGGER.log(Level.FINER,
955+
if (LOGGER.isLoggable(Level.FINEST)) {
956+
LOGGER.log(Level.FINEST,
957957
"{0}: chosen by precise magic: {1}", new Object[]{
958958
file, fac.getClass().getSimpleName() });
959959
}
@@ -974,8 +974,8 @@ private static AnalyzerFactory findForStream(InputStream in,
974974
if (!matcher.getIsPreciseMagic()) {
975975
fac = matcher.isMagic(content, in);
976976
if (fac != null) {
977-
if (LOGGER.isLoggable(Level.FINER)) {
978-
LOGGER.log(Level.FINER,
977+
if (LOGGER.isLoggable(Level.FINEST)) {
978+
LOGGER.log(Level.FINEST,
979979
"{0}: chosen by imprecise magic: {1}",
980980
new Object[]{file,
981981
fac.getClass().getSimpleName() });
@@ -996,8 +996,8 @@ private static AnalyzerFactory findMagicString(String opening,
996996
String fragment = getWords(opening, 2);
997997
AnalyzerFactory fac = magics.get(fragment);
998998
if (fac != null) {
999-
if (LOGGER.isLoggable(Level.FINER)) {
1000-
LOGGER.log(Level.FINER, "{0}: chosen by magic {2}: {1}",
999+
if (LOGGER.isLoggable(Level.FINEST)) {
1000+
LOGGER.log(Level.FINEST, "{0}: chosen by magic {2}: {1}",
10011001
new Object[]{file, fac.getClass().getSimpleName(),
10021002
fragment});
10031003
}
@@ -1008,8 +1008,8 @@ private static AnalyzerFactory findMagicString(String opening,
10081008
fragment = getWords(opening, 1);
10091009
fac = magics.get(fragment);
10101010
if (fac != null) {
1011-
if (LOGGER.isLoggable(Level.FINER)) {
1012-
LOGGER.log(Level.FINER, "{0}: chosen by magic {2}: {1}",
1011+
if (LOGGER.isLoggable(Level.FINEST)) {
1012+
LOGGER.log(Level.FINEST, "{0}: chosen by magic {2}: {1}",
10131013
new Object[]{file, fac.getClass().getSimpleName(),
10141014
fragment});
10151015
}
@@ -1022,8 +1022,8 @@ private static AnalyzerFactory findMagicString(String opening,
10221022
String magic = entry.getKey();
10231023
if (opening.startsWith(magic)) {
10241024
fac = entry.getValue();
1025-
if (LOGGER.isLoggable(Level.FINER)) {
1026-
LOGGER.log(Level.FINER,
1025+
if (LOGGER.isLoggable(Level.FINEST)) {
1026+
LOGGER.log(Level.FINEST,
10271027
"{0}: chosen by magic(substr) {2}: {1}", new Object[]{
10281028
file, fac.getClass().getSimpleName(), magic});
10291029
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/MandocRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ public void start() throws IOException, MandocException {
9999
command.add("os=" + oo);
100100
}
101101

102-
if (LOGGER.isLoggable(Level.FINE)) {
102+
if (LOGGER.isLoggable(Level.FINER)) {
103103
StringBuilder sb = new StringBuilder();
104104
command.forEach((s) -> {
105105
sb.append(s).append(" ");
106106
});
107107
String cmd = sb.toString();
108-
LOGGER.log(Level.FINE, "Executing mandoc command [{0}]", cmd);
108+
LOGGER.log(Level.FINER, "Executing mandoc command [{0}]", cmd);
109109
}
110110

111111
ProcessBuilder processBuilder = new ProcessBuilder(command);

opengrok-indexer/src/main/java/org/opengrok/indexer/index/DefaultIndexChangedListener.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,25 @@ public class DefaultIndexChangedListener implements IndexChangedListener {
4141

4242
@Override
4343
public void fileAdd(String path, String analyzer) {
44-
LOGGER.log(Level.INFO, "Add: {0} ({1})", new Object[]{path, analyzer});
44+
if (LOGGER.isLoggable(Level.FINE)) {
45+
LOGGER.log(Level.FINE, "Add: {0} ({1})", new Object[]{path, analyzer});
46+
}
4547
}
4648

4749
@Override
4850
public void fileRemove(String path) {
49-
LOGGER.log(Level.INFO, "Remove file:{0}", path);
51+
LOGGER.log(Level.FINE, "Remove file:{0}", path);
5052
}
5153
@Override
5254
public void fileUpdate(String path) {
53-
LOGGER.log(Level.INFO, "Update: {0}", path);
55+
LOGGER.log(Level.FINE, "Update: {0}", path);
5456
}
5557

5658
@Override
5759
public void fileAdded(String path, String analyzer) {
58-
LOGGER.log(Level.FINER, "Added: {0} ({1})", new Object[]{path, analyzer});
60+
if (LOGGER.isLoggable(Level.FINER)) {
61+
LOGGER.log(Level.FINER, "Added: {0} ({1})", new Object[]{path, analyzer});
62+
}
5963
}
6064

6165
@Override

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,8 @@ public void run() {
241241
*
242242
* @param listener where to signal the changes to the database
243243
* @param paths list of paths to be indexed
244-
* @throws IOException if an error occurs
245244
*/
246-
public static void update(IndexChangedListener listener, List<String> paths)
247-
throws IOException {
245+
public static void update(IndexChangedListener listener, List<String> paths) {
248246
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
249247
IndexerParallelizer parallelizer = env.getIndexerParallelizer();
250248
List<IndexDatabase> dbs = new ArrayList<>();
@@ -350,20 +348,12 @@ public boolean addDirectory(String dir) {
350348
return false;
351349
}
352350

353-
private int getFileCount(File sourceRoot, String dir) throws IOException {
354-
int file_cnt = 0;
351+
private void showFileCount(
352+
String dir, IndexDownArgs args, Statistics elapsed) {
355353
if (RuntimeEnvironment.getInstance().isPrintProgress()) {
356-
IndexDownArgs args = new IndexDownArgs();
357-
args.count_only = true;
358-
359-
Statistics elapsed = new Statistics();
360-
LOGGER.log(Level.INFO, "Counting files in {0} ...", dir);
361-
indexDown(sourceRoot, dir, args);
362354
elapsed.report(LOGGER, String.format("Need to process: %d files for %s",
363355
args.cur_count, dir));
364356
}
365-
366-
return file_cnt;
367357
}
368358

369359
private void markProjectIndexed(Project project) {
@@ -495,18 +485,15 @@ public void update() throws IOException {
495485
// The actual indexing happens in indexParallel().
496486

497487
IndexDownArgs args = new IndexDownArgs();
498-
args.est_total = getFileCount(sourceRoot, dir);
499-
500-
args.cur_count = 0;
501488
Statistics elapsed = new Statistics();
502489
LOGGER.log(Level.INFO, "Starting traversal of directory {0}", dir);
503490
indexDown(sourceRoot, dir, args);
504-
elapsed.report(LOGGER, String.format("Done traversal of directory %s", dir));
491+
showFileCount(dir, args, elapsed);
505492

506493
args.cur_count = 0;
507494
elapsed = new Statistics();
508495
LOGGER.log(Level.INFO, "Starting indexing of directory {0}", dir);
509-
indexParallel(args);
496+
indexParallel(dir, args);
510497
elapsed.report(LOGGER, String.format("Done indexing of directory %s", dir));
511498

512499
// Remove data for the trailing terms that indexDown()
@@ -804,7 +791,6 @@ private void addFile(File file, String path, Ctags ctags)
804791

805792
private AbstractAnalyzer getAnalyzerFor(File file, String path)
806793
throws IOException {
807-
AbstractAnalyzer fa;
808794
try (InputStream in = new BufferedInputStream(
809795
new FileInputStream(file))) {
810796
return AnalyzerGuru.getAnalyzer(in, path);
@@ -1037,12 +1023,24 @@ private boolean isLocal(String path) {
10371023
return local;
10381024
}
10391025

1040-
private void printProgress(int currentCount, int totalCount) {
1041-
if (RuntimeEnvironment.getInstance().isPrintProgress()
1042-
&& totalCount > 0 && LOGGER.isLoggable(Level.INFO)) {
1043-
LOGGER.log(Level.INFO, "Progress: {0} ({1}%)",
1044-
new Object[]{currentCount,
1045-
(currentCount * 100.0f / totalCount)});
1026+
private void printProgress(String dir, int currentCount, int totalCount) {
1027+
if (totalCount > 0 && RuntimeEnvironment.getInstance().isPrintProgress()) {
1028+
Level currentLevel;
1029+
if (currentCount <= 1 || currentCount >= totalCount ||
1030+
currentCount % 100 == 0) {
1031+
currentLevel = Level.INFO;
1032+
} else if (currentCount % 50 == 0) {
1033+
currentLevel = Level.FINE;
1034+
} else if (currentCount % 10 == 0) {
1035+
currentLevel = Level.FINER;
1036+
} else {
1037+
currentLevel = Level.FINEST;
1038+
}
1039+
if (LOGGER.isLoggable(currentLevel)) {
1040+
LOGGER.log(currentLevel, "Progress: {0} ({1}%) for {2}",
1041+
new Object[]{currentCount, currentCount * 100.0f /
1042+
totalCount, dir});
1043+
}
10461044
}
10471045
}
10481046

@@ -1103,9 +1101,6 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
11031101
indexDown(file, path, args);
11041102
} else {
11051103
args.cur_count++;
1106-
if (args.count_only) {
1107-
continue;
1108-
}
11091104

11101105
if (uidIter != null) {
11111106
path = Util.fixPathIfWindows(path);
@@ -1163,10 +1158,11 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
11631158

11641159
/**
11651160
* Executes the second, parallel stage of indexing.
1161+
* @param dir the parent directory (when appended to SOURCE_ROOT)
11661162
* @param args contains a list of files to index, found during the earlier
11671163
* stage
11681164
*/
1169-
private void indexParallel(IndexDownArgs args) throws IOException {
1165+
private void indexParallel(String dir, IndexDownArgs args) {
11701166

11711167
int worksCount = args.works.size();
11721168
if (worksCount < 1) {
@@ -1227,7 +1223,7 @@ private void indexParallel(IndexDownArgs args) throws IOException {
12271223
}
12281224

12291225
int ncount = currentCounter.incrementAndGet();
1230-
printProgress(ncount, worksCount);
1226+
printProgress(dir, ncount, worksCount);
12311227
return ret;
12321228
}
12331229
}))).get();
@@ -1820,9 +1816,7 @@ private boolean xrefExistsFor(String path) {
18201816
}
18211817

18221818
private class IndexDownArgs {
1823-
boolean count_only;
18241819
int cur_count;
1825-
int est_total;
18261820
final List<IndexFileWork> works = new ArrayList<>();
18271821
}
18281822

opengrok-indexer/src/main/java/org/opengrok/indexer/search/Results.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,13 @@ private static void printPlain(PrintPlainFinalArgs fargs, Document doc,
302302
fargs.xrefPrefix, fargs.morePrefix, rpath, tags, true,
303303
isDefSearch, null, scopes);
304304
} catch (IOException ex) {
305-
LOGGER.log(Level.WARNING, String.format("No context for %s",
306-
sourceFile, ex));
305+
String errMsg = String.format("No context for %s", sourceFile);
306+
if (LOGGER.isLoggable(Level.FINE)) {
307+
// WARNING but with FINE detail
308+
LOGGER.log(Level.WARNING, errMsg, ex);
309+
} else {
310+
LOGGER.log(Level.WARNING, errMsg);
311+
}
307312
}
308313
}
309314
}

0 commit comments

Comments
 (0)