Skip to content

Commit be32875

Browse files
committed
Change print_record() Fix function to optionally output the internal representation. (#238, 74dc79f)
This is the only way to see the record without interference from the encoding process.
1 parent fe6dc41 commit be32875

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ Options:
352352
- `footer`: Footer which is output after the record. (Default: `\n`)
353353
- `header`: Header which is output before the record. (Default: Empty string)
354354
- `id`: Field name which contains the record ID; if found, will be available for inclusion in `prefix` and `destination`. (Default: `_id`)
355+
- `internal`: Whether to print the record's internal representation instead of JSON. (Default: `false`)
355356
- `pretty`: Whether to use pretty printing. (Default: `false`)
356357

357358
```perl

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
235235
final String destination = options.getOrDefault("destination", ObjectWriter.STDOUT);
236236
final Value idValue = record.get(options.getOrDefault("id", StandardEventNames.ID));
237237

238+
final boolean internal = getBoolean(options, "internal");
238239
final boolean pretty = getBoolean(options, "pretty");
239240

240241
final LongAdder counter = scopedCounter.computeIfAbsent(metafix, k -> new LongAdder());
@@ -249,11 +250,21 @@ public void apply(final Metafix metafix, final Record record, final List<String>
249250
withOption(options, "footer", writer::setFooter);
250251
withOption(options, "header", writer::setHeader);
251252

252-
try {
253-
writer.process(prefix + record.toJson(pretty));
253+
if (internal) {
254+
if (pretty) {
255+
record.forEach((f, v) -> writer.process(prefix + f + "=" + v));
256+
}
257+
else {
258+
writer.process(prefix + record);
259+
}
254260
}
255-
catch (final IOException e) {
256-
// Log a warning? Print string representation instead?
261+
else {
262+
try {
263+
writer.process(prefix + record.toJson(pretty));
264+
}
265+
catch (final IOException e) {
266+
// Log a warning? Print string representation instead?
267+
}
257268
}
258269

259270
writer.closeStream();

0 commit comments

Comments
 (0)