Skip to main content

Log dictionaries to file using the MessagePack serialization format.

Project description

mpacklog

Build Coverage Documentation C++ version Release

Log dictionaries to MessagePack files in C++ and Python.

Installation

Python

pip install mpacklog

Bazel

Add a git repository rule to your Bazel WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "mpacklog",
    remote = "https://github.com/stephane-caron/mpacklog.git",
    tag = "v1.0.0",
)

You can then use the @mpacklog dependency for C++ targets, or the @mpacklog//:python dependency for Python targets.

Usage

C++

The C++ implementation uses multi-threading. Add messages to the log using the put function, they will be written to file in the background.

#include <mpacklog/Logger.h>
#include <palimpsest/Dictionary.h>

int main() {
    mpacklog::Logger logger("output.mpack");

    for (unsigned bar = 0; bar < 1000u; ++bar) {
        palimpsest::Dictionary dict;
        dict("foo") = bar;
        dict("something") = "else";
        logger.put(dict):
    }
}

Python

The Python implementation uses asynchronous I/O. Add messages to the log using the put function, have them written to file in the separate write coroutine.

import asyncio
import mpacklog

async def main():
    logger = mpacklog.Logger("output.mpack")

    await asyncio.gather(
        main_loop(logger),
        logger.write(),
    )

async def main_loop(logger):
    for bar in range(1000):
        await asyncio.sleep(1e-3)
        await logger.put({"foo": bar, "something": "else"})
    await logger.stop()

if __name__ == "__main__":
    asyncio.run(main())

Command-line

If you pip-installed mpacklog, you can use the mpacklog command to dump logs to JSON:

mpacklog dump my_log.mpack

Alternatively and more generally, two great tools to manipulate logs from the command line are:

  • rq: transform from/to MessagePack, JSON, YAML, TOML, ...
  • jq: manipulate JSON series to add, remove or extend fields

For instance, mpacklog dump is equivalent to:

rq -mJ < my_log.mpack

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpacklog-2.0.0.tar.gz (67.3 kB view details)

Uploaded Source

Built Distribution

mpacklog-2.0.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file mpacklog-2.0.0.tar.gz.

File metadata

  • Download URL: mpacklog-2.0.0.tar.gz
  • Upload date:
  • Size: 67.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for mpacklog-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2541abc46a0e11cdd5bce93eed7bd6a92c4e8ed57bd61bde6a479cecd6648d03
MD5 1a75005744a6f2b3ff7b29ccc24fe748
BLAKE2b-256 ad897465a517330ea9ae22850289ca7cbd11caff2a514affdb259a6667f00868

See more details on using hashes here.

Provenance

File details

Details for the file mpacklog-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: mpacklog-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for mpacklog-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f565ec96b1209bddd4dd86654f3201587f0bd8e268d15bdf15608b851348edda
MD5 cbaef843db92d20b7092b51100795446
BLAKE2b-256 ad0fc7132afd5671620d50af359c1b72ad6808f1e031ac6e5530728547e3eadb

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page