Description
Allow users to customize the output format and add custom fields for enhanced log readability.
Describe the problem this feature request solves
Currently, pamburus/hl
provides a good way to read JSON log lines. However, it lacks the ability to customize the output format. This limits the user's ability to tailor the output to their specific needs and makes it difficult to add custom fields for more context or analysis.
Describe the solution you'd like
I propose adding the following features:
- Customizable Output Format: Allow users to define their own output format using a template or configuration file. This would enable users to control:
- The order of fields
- The display format of each field (e.g., date/time formatting, number formatting)
- The inclusion/exclusion of specific fields
- Adding separators or other visual elements
- Custom Fields: Enable users to add custom fields to the output. These fields could be derived from existing fields using expressions or functions. For example:
- Calculate the duration between two timestamps
- Extract parts of a string using regular expressions
- Perform simple calculations on numeric fields
Describe alternatives you've considered
I have considered using other tools for reading JSON logs, but pamburus/hl
is currently the best in terms of its core functionality. However, the lack of output customization hinders its usefulness for more advanced use cases.
Additional context
This feature would greatly enhance the flexibility and usability of pamburus/hl
, making it a more powerful tool for analyzing JSON log data. It would allow users to create highly customized views of their logs, tailored to their specific needs.
Example use case:
Imagine a log line like this:
{"timestamp": "2024-10-27T10:00:00Z", "level": "INFO", "message": "Request received", "request_id": "12345", "duration_ms": 150}
With customizable output, I could define a format like:
[{{timestamp | date:"%Y-%m-%d %H:%M:%S"}}] [{{level}}] (Request ID: {{request_id}}) - {{message}} (Duration: {{duration_ms}}ms)
Resulting in an output like:
[2024-10-27 10:00:00] [INFO] (Request ID: 12345) - Request received (Duration: 150ms)
This provides a much clearer and more informative view of the log data.