Metadata-Version: 2.4
Name: mflt-compact-log
Version: 0.2.1
Summary: Memfault compact log utilities
Author-email: Memfault <hello@memfault.com>
Requires-Python: <4.0,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cbor2<6,>=5
Requires-Dist: prettytable<4,>=3
Requires-Dist: pyelftools>=0.31
Requires-Dist: pyparsing<4,>=3.1.4
Requires-Dist: typing_extensions<5,>=4.12.2
Dynamic: license-file

# Memfault Compact Log Library

This library enables decoding Memfault-flavored compact logs. For background
information on compact logs, see here:

<https://mflt.io/compact-logs>

## Usage

Some brief usage information below. See the source for detailed usage.

### Extracting compact log format strings from .elf

To extract the format strings from the symbol file:

```python
from mflt_compact_log.log_fmt import LogFormatElfSectionParser

elf = "path to elf file"
# parse the elf file
mappings = LogFormatElfSectionParser.get_mapping_from_elf_file(elf)
# 'mappings' is a dictionary mapping log id to LogFormatInfo data
print(mappings)

>>> {8: LogFormatInfo(filename='./main/console_example_main.c', line=245, n_args=0, fmt='This is a compact log example')}
```

### Decoding compact logs

To apply the format string to raw compact log data:

```python
from mflt_compact_log import CompactLogDecoder

# example format string; this could instead be retrieved from the elf file
fmt = "An Integer Format String: %d"

# compact log hex encoded raw data
compact_log = "820A0B"

# decode the log!
compact_log_as_bytes = bytes.fromhex(compact_log)
log = CompactLogDecoder.from_cbor_array(fmt, compact_log_as_bytes)
log.decode()
>>> 'An Integer Format String: 11'
```

## Changes

### [0.2.1] - 2026-01-20

- Add project description to `pyproject.toml`

### [0.2.0] - 2025-11-17

- Remove support for Python < 3.10
- Remove `click` dependency
- Add support for Truncated Compact Log entries
- The command line tools, `mflt-compact-log.log_fmt` and
  `mflt-compact-log.decode_compact_log`, have been moved into subcommands under
  `mflt-compact-log`:

  - `mflt-compact-log log-fmt`
  - `mflt-compact-log decode`

  See `mflt-compact-log --help` for details.

### [0.1.1] - 2024-11-14

- Fix some missing dependencies that are required as of the `0.1.0` release.

### [0.1.0] - 2024-11-08

- Replace the wasmer-based decoder with a pure Python implementation

### [0.0.5] - 2024-08-29

- Improve the output of `mflt-compact-log.log_fmt` for log format strings
  containing non-printable characters

### [0.0.4] - 2024-06-13

- Source pyelftools from <https://pypi.org/project/pyelftools/> again, as the
  required bugfixes have been merged upstream. See notes of 0.0.3 below.

### [0.0.3] - 2024-01-30

- Source pyelftools from <https://github.com/memfault/pyelftools> while we are
  waiting for 2 bugfixes to get merged upstream
  (<https://github.com/eliben/pyelftools/pull/537> and
  <https://github.com/eliben/pyelftools/pull/538>).

### 0.0.2

- support Python 3.9 and 3.10
- update `prettytable` dependency from `0.7.2` to `3.4.1`
- update `pyelftools` dependency from `^0.28.0` to `^0.29.0`
