-
Notifications
You must be signed in to change notification settings - Fork 3
Logmefmt
logmefmt converts logme records between text, JSON and XML formats. It is intended for offline log processing: converting existing text logs to structured output, renaming fields, and finalizing append-friendly structured streams into complete JSON or XML documents.
logmefmt - convert logme records between text, JSON and XML formats
Copyright (c) EFM Software
Usage:
logmefmt --input text|json|xml --output text|json|xml [options]
Options:
--input FORMAT Input format: text, json, xml
--output FORMAT Output format: text, json, xml
--in FILE Read from FILE instead of stdin
--out FILE Write to FILE instead of stdout
--finalize Complete JSON/XML output document
--root NAME XML root element for --finalize (default: log)
--field OLD=NEW Rename field on both input and output sides
--input-field OLD=NEW Rename field before conversion
--output-field OLD=NEW Rename field after conversion
--help Show this help
Running logmefmt without arguments prints the same help and exits. It does not wait for input from stdin by default.
When the input format is text, logmefmt parses known logme text prefixes and extracts structured fields where possible:
timestamplevelprocess_idthread_idchannelsubsystemfilelinemethodmessage
The parser is conservative. If a part is not present, the field is simply omitted. The remaining text becomes message, so the original log text is not dropped.
printf '2026-05-03 10:00:00:123 D [04D2:162E] {NET} #HTTP main.cpp(42): Connect(): connected\n' \
| logmefmt --input text --output jsonOutput:
{"timestamp":"2026-05-03 10:00:00:123","level":"DEBUG","process_id":"04D2","thread_id":"162E","channel":"NET","subsystem":"HTTP","file":"main.cpp","line":"42","method":"Connect","message":"connected"}What happens:
- the timestamp is written as
timestamp -
Dis converted toDEBUG -
[04D2:162E]becomesprocess_idandthread_id -
{NET}becomeschannel -
#HTTPbecomessubsystem -
main.cpp(42)becomesfileandline -
Connect():becomesmethod - the rest of the line becomes
message
printf '2026-05-03 10:00:00:123 E [04D2:162E] {NET} #HTTP main.cpp(42): Connect(): failed\n' \
| logmefmt --input text --output xmlOutput:
<event><timestamp>2026-05-03 10:00:00:123</timestamp><level>ERROR</level><process_id>04D2</process_id><thread_id>162E</thread_id><channel>NET</channel><subsystem>HTTP</subsystem><file>main.cpp</file><line>42</line><method>Connect</method><message>failed</message></event>This produces one <event> element for the input line. Without --finalize, XML output is a stream of events, not a complete XML document.
printf 'plain application output\n' \
| logmefmt --input text --output xmlOutput:
<event><message>plain application output</message></event>The line does not match the known logme prefix pattern, so no artificial fields are created.
printf 'first\nsecond\n' \
| logmefmt --input text --output json --finalizeOutput:
[
{"message":"first"},
{"message":"second"}
]Use this when the result must be a valid standalone JSON document. Without --finalize, the output is a JSON-lines style stream of separate objects.
printf 'first\nsecond\n' \
| logmefmt --input text --output xml --finalize --root eventsOutput:
<events>
<event><message>first</message></event>
<event><message>second</message></event>
</events>--root changes the document root name used only when XML finalization is enabled.
printf '2026-05-03 10:00:00:123 W [04D2:162E] {NET} #HTTP retry\n' \
| logmefmt --input text --output json --field message=msg --field level=severityOutput:
{"timestamp":"2026-05-03 10:00:00:123","severity":"WARN","process_id":"04D2","thread_id":"162E","channel":"NET","subsystem":"HTTP","msg":"retry"}--field OLD=NEW renames a field on both the input and output sides. Use --input-field or --output-field when renaming is needed only before or only after conversion.
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering