elastic / elastic/logstash

Sprintf should allow for number formatting

Open
#5,850 0 comments 0 reactions 0 assignees View on GitHub
design discuss enhancement v6.0.0
Dominant language
Java
Stars
14.9k
Forks
3.5k
Avg merge
19h 14m
Merged PRs (30d)
63

Description

## Problem

Our `sprintf` function really just does interpolation. This is insufficient if you want more specific string formatting, say limiting a `float` to two places of precision.

One particularly problematic area here is the case of `BigDecimal` values, as seen in #5808 . All `BigDecimal` values print out as scientific notation, even very small ones like `0.96E2%` which is really terrible to read.
## Solution

We should add a new syntax that uses java's [Formatter](https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) to handle this. The syntax could look like: `"Here's a message with a %{fieldname:0.2f}". In this case we've added the format after the colon much like a grok pattern.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.