Skip to content

Commit acab9b7

Browse files
authored
TIKA-4742 -- refactor logging for beta-1 (#2844)
1 parent 2bab6d4 commit acab9b7

47 files changed

Lines changed: 217 additions & 149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/modules/ROOT/pages/pipes/troubleshooting.adoc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ pick them up automatically. The default `pipes-fork-server-default-log4j2.xml`
6262
writes to `SYSTEM_ERR`, so inheritance is what makes those records visible
6363
to your observability stack.
6464

65+
=== Telling fork lines from parent lines
66+
67+
Since the fork and parent share a single stdio stream, the bundled
68+
`pipes-fork-server-default-log4j2.xml` pattern adds two orthogonal markers
69+
so you can read the interleaved output:
70+
71+
* `[fork]` -- present only on lines emitted by a forked `PipesServer`
72+
JVM. Lines from the parent process (`PipesClient`, `AsyncProcessor`,
73+
`ConnectionHandler`, `tika-server`, `tika-grpc`, etc.) do not carry
74+
this tag. Different mechanism on each side: the fork has it injected
75+
via the bundled pattern's literal `[fork]` token; the parent does
76+
not include it in its own log4j2/logback patterns.
77+
78+
* `pipesClientId=N` -- *the same value on both sides of a pair*. The
79+
parent's `PipesClient #N` always connects to the fork running with
80+
`-DpipesClientId=N`, so the same N enables correlation across the
81+
process boundary. Use it to gather every log line about one
82+
conversation, regardless of which side emitted them.
83+
84+
A typical interleaved snippet:
85+
86+
[source]
87+
----
88+
INFO [main] 14:23:45,123 [fork] pipesClientId=0 o.a.t.p.c.server.PipesServer received SHUT_DOWN
89+
DEBUG [Thread-3] 14:23:45,124 o.a.t.p.c.async.AsyncProcessor pipesClientId=0, status=PARSE_SUCCESS
90+
----
91+
92+
The first line is from inside fork 0 (`[fork]` present). The second is
93+
the parent talking *about* fork 0 (`[fork]` absent, but the same client
94+
id appears in the message body).
95+
6596
If you don't want the pipes-server's output interleaved with your own --
6697
e.g. an embedded use case where the parent is producing its own structured
6798
stdout, or a test environment where you want a quieter console -- set the
@@ -112,6 +143,55 @@ When the watcher fires, the child exits via `System.exit`, which runs
112143
`AbstractExternalProcessParser`'s shutdown hook and cleans up any
113144
in-flight external subprocesses.
114145

146+
== Log levels and sensitive data
147+
148+
Tika Pipes treats `FetchKey` and `EmitKey` values as potentially sensitive --
149+
they typically contain file paths, URLs, object-store keys, or other identifiers
150+
that may be private to the data owner. The convention across pipes core and the
151+
bundled plugins is:
152+
153+
[cols="1,3"]
154+
|===
155+
|Level |What is logged
156+
157+
|`ERROR` / `WARN`
158+
|Failures, exceptions, and configuration problems. *Never* the literal
159+
`fetchKey`/`emitKey` or any file content. When a failure refers to a
160+
specific document, it is identified by the non-sensitive `FetchEmitTuple.id`
161+
(e.g. `parse exception: id=abc-123`).
162+
163+
|`INFO`
164+
|Lifecycle events -- server start/stop, plugin start/stop, mode banners,
165+
restart events. Per-document or per-request lines have been demoted from
166+
INFO to DEBUG so production logs stay quiet.
167+
168+
|`DEBUG`
169+
|Per-document progress and aggregated counts (e.g. `pipesClientId=2,
170+
status=PARSE_SUCCESS`, `successfully emitted N docs`). Safe to enable in
171+
production for troubleshooting; correlation is by `FetchEmitTuple.id` only.
172+
173+
|`TRACE`
174+
|Verbose per-fetch and per-emit detail including the literal
175+
`fetchKey`/`emitKey` (URL, S3 key, blob path, etc.). Enable only when you
176+
need to correlate a Tika log line back to a specific resource, and accept
177+
that those keys will appear in the log destination.
178+
|===
179+
180+
The fetcher and emitter SPIs (`Fetcher.fetch`, `Emitter.emit`,
181+
`StreamEmitter.emit`) receive the literal key but not the tuple id, so
182+
plugin code can only log the literal key. Keeping that at TRACE keeps it
183+
out of any log destination that is configured at DEBUG or higher.
184+
185+
If you write your own fetcher or emitter plugin, please follow the same
186+
convention: literal keys at TRACE, everything else at DEBUG or above with
187+
no key in the message.
188+
189+
NOTE: Exception messages thrown out of a fetcher may still include
190+
response-body bytes for HTTP-style fetchers (configurable via
191+
`maxErrMsgSize` on `HttpFetcherConfig`). Those bytes appear in whatever
192+
log catches the thrown exception. Lower `maxErrMsgSize` -- or set it to
193+
zero -- if your responses can contain sensitive data.
194+
115195
== Configuration knobs reference
116196

117197
[cols="2,3"]

tika-core/src/main/resources/pipes-fork-server-default-log4j2.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

tika-parsers/tika-parsers-extended/tika-parser-ocr-encode-module/src/main/java/org/apache/tika/parser/ocrencode/EncodeOCRParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void doEncode(
229229
int processed = counter != null
230230
? counter.get()
231231
: config.getMaxImagesToOcr();
232-
LOG.info("Skipping OCR encode for image because "
232+
LOG.debug("Skipping OCR encode for image because "
233233
+ "the configured limit of {} images "
234234
+ "has been reached ({} already processed)",
235235
config.getMaxImagesToOcr(), processed);
@@ -288,7 +288,7 @@ private void encodeToBase64(
288288
xhtml.endElement(XHTML, "div", "div");
289289

290290
long durationMs = (System.nanoTime() - startTime) / 1_000_000;
291-
LOG.info("OCR encoding - input file size: {} bytes, "
291+
LOG.debug("OCR encoding - input file size: {} bytes, "
292292
+ "output size: {} characters, "
293293
+ "time taken: {} ms",
294294
fileSize, sink.totalChars(), durationMs);

tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/ner/grobid/GrobidNERecogniser.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public GrobidNERecogniser() {
7474
this.available = isServerAlive(restHostUrlStr);
7575

7676
} catch (Exception e) {
77-
LOG.info(e.getMessage(), e);
77+
LOG.warn(e.getMessage(), e);
7878
}
7979
}
8080

@@ -88,10 +88,10 @@ private static boolean isServerAlive(String restHostUrlStr) {
8888
if (responseCode == 200) {
8989
available = true;
9090
} else {
91-
LOG.info("Grobid Quantities REST Server is not running");
91+
LOG.warn("Grobid Quantities REST Server is not running");
9292
}
9393
} catch (Exception e) {
94-
LOG.info("Grobid Quantities REST Server is not running", e);
94+
LOG.warn("Grobid Quantities REST Server is not running", e);
9595
}
9696

9797
return available;
@@ -146,7 +146,7 @@ public JSONArray convertToJSONArray(JSONObject obj, String key) {
146146
try {
147147
jsonArray = (JSONArray) obj.get(key);
148148
} catch (Exception e) {
149-
LOG.info(e.getMessage(), e);
149+
LOG.warn(e.getMessage(), e);
150150
}
151151
return jsonArray;
152152
}
@@ -162,7 +162,7 @@ public JSONObject convertToJSONObject(String jsonString) {
162162
try {
163163
jsonObject = (JSONObject) parser.parse(jsonString);
164164
} catch (Exception e) {
165-
LOG.info(e.getMessage(), e);
165+
LOG.warn(e.getMessage(), e);
166166
}
167167
return jsonObject;
168168
}
@@ -261,7 +261,7 @@ public Map<String, Set<String>> recognise(String text) {
261261
}
262262
}
263263
} catch (Exception e) {
264-
LOG.info(e.getMessage(), e);
264+
LOG.warn(e.getMessage(), e);
265265

266266
}
267267
ENTITY_TYPES.clear();

tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/ner/nltk/NLTKNERecogniser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public NLTKNERecogniser() {
7979
if (responseCode == 200) {
8080
available = true;
8181
} else {
82-
LOG.info("NLTKRest Server is not running");
82+
LOG.debug("NLTKRest Server is not running");
8383
}
8484

8585
} catch (Exception e) {

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/detect/microsoft/POIFSContainerDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ private Set<String> getTopLevelNames(TikaInputStream stream) throws IOException
560560
Path file = stream.getPath();
561561

562562
if (file == null) {
563-
LOG.warn("Stream does not support file access; skipping POIFS detection");
563+
LOG.debug("Stream does not support file access; skipping POIFS detection");
564564
return Collections.emptySet();
565565
}
566566

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/libpst/LibPstParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private void _parse(Path pst, ContentHandler contentHandler, Metadata metadata,
101101
throw new TikaException("Timeout exception: " + fileProcessResult.getProcessTimeMillis());
102102
}
103103
if (fileProcessResult.getExitValue() != 0) {
104-
LOGGER.warn("libpst bad exit value {}: {}", fileProcessResult.getExitValue(), fileProcessResult.getStderr());
104+
LOGGER.warn("libpst bad exit value {}", fileProcessResult.getExitValue());
105+
LOGGER.debug("libpst stderr: {}", fileProcessResult.getStderr());
105106
throw new TikaException("Bad exit value: " + fileProcessResult.getExitValue());
106107
}
107108
xhtml.endDocument();

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/msg/ExtendedMetadataExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private static ClassID parseClassId(String s, Map<String, ClassID> knownClassIDs
261261
if (knownClassIDs.containsKey(s)) {
262262
return knownClassIDs.get(s);
263263
}
264-
LOGGER.warn("Add '{}' to list of known property set IDs", s);
264+
LOGGER.debug("Add '{}' to list of known property set IDs", s);
265265
ClassID classID = new ClassID(s);
266266
knownClassIDs.put(classID.toUUIDString(), classID);
267267
return classID;

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/ooxml/TikaSheetXMLHandler.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ public void startElement(String uri, String localName, String qName,
147147
String ref = attributes.getValue("ref");
148148
if (ref != null) {
149149
fIsOpen = true;
150-
} else {
151-
if (formulasNotResults) {
152-
LOG.warn("shared formulas not yet supported!");
153-
}
154150
}
151+
// shared-formula reference without a `ref` attribute is not yet supported
155152
} else {
156153
fIsOpen = true;
157154
}

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/hwp/HwpTextExtractorV5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void parseBodyText(FileHeader header, DirectoryNode root, XHTMLContentHa
264264
parse(reader, xhtml);
265265

266266
} else {
267-
LOG.warn("Unknown Entry '{}'({})", entry.getName(), entry);
267+
LOG.debug("Unknown Entry '{}'({})", entry.getName(), entry);
268268
}
269269
}
270270
}
@@ -309,7 +309,7 @@ private void parseViewText(FileHeader header, DirectoryNode root, XHTMLContentHa
309309
IOUtils.closeQuietly(input);
310310
}
311311
} else {
312-
LOG.warn("unknown Entry '{}'({})", entry.getName(), entry);
312+
LOG.debug("unknown Entry '{}'({})", entry.getName(), entry);
313313
}
314314
}
315315
}

0 commit comments

Comments
 (0)