Skip to content

Commit 6f22490

Browse files
committed
Change print_record() Fix function prefix parameter to format string. (#238)
1 parent 74dc79f commit 6f22490

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ Prints the current record as JSON either to standard output or to a file.
311311

312312
Parameters:
313313

314-
- `prefix` (optional): Prefix to print before the record. (Default: Empty string)
314+
- `prefix` (optional): Prefix to print before the record; may include [format directives](https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax) for counter and record ID (in that order). (Default: Empty string)
315315

316316
Options:
317317

@@ -320,7 +320,7 @@ Options:
320320
- `encoding` (file output only): Encoding used by the underlying writer. (Default: `UTF-8`)
321321
- `footer`: Footer which is output after the record. (Default: `\n`)
322322
- `header`: Header which is output before the record. (Default: Empty string)
323-
- `id`: Field name which contains the record ID; if found, will be included before the prefix. (Default: `_id`)
323+
- `id`: Field name which contains the record ID; if found, will be available for inclusion in `prefix` and `destination`. (Default: `_id`)
324324
- `pretty`: Whether to use pretty printing. (Default: `false`)
325325

326326
```perl
@@ -330,7 +330,7 @@ print_record(["<prefix>"][, <options>...])
330330
E.g.:
331331

332332
```perl
333-
print_record("Before transformation")
333+
print_record("%d) Before transformation: ")
334334
print_record(destination: "record-%2$s.json", id: "001", pretty: "true")
335335
print_record(destination: "record-%03d.json.gz", header: "After transformation: ")
336336
```

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,11 @@ public void apply(final Metafix metafix, final Record record, final List<String>
224224

225225
final boolean pretty = getBoolean(options, "pretty");
226226

227-
final String id = Value.isNull(idValue) ? "" : idValue.toString();
228-
final String prefix = (id.isEmpty() ? "" : "[" + id + "] ") + (params.isEmpty() ? "" : params.get(0) + ": ");
229-
230227
final LongAdder counter = scopedCounter.computeIfAbsent(metafix, k -> new LongAdder());
231228
counter.increment();
232229

230+
final String id = Value.isNull(idValue) ? "" : idValue.toString();
231+
final String prefix = params.isEmpty() ? "" : String.format(params.get(0), counter.sum(), id);
233232
final ObjectWriter<String> writer = new ObjectWriter<>(String.format(destination, counter.sum(), id));
234233

235234
withOption(options, "compression", writer::setCompression);

0 commit comments

Comments
 (0)