Skip to main content

Prepare lines of text for easy consumption

Project description

https://travis-ci.com/tonysyu/linecook.svg?branch=master https://codecov.io/gh/tonysyu/linecook/branch/master/graph/badge.svg https://readthedocs.org/projects/linecook/badge/

See the documentation at https://linecook.readthedocs.io

NOTE: Most of this is just planning, and doesn’t actually work yet.

This was originally designed as a tool to transform logging output into a form that I’d prefer to consume:

$ echo "Can I have a cheeseburger?" | linecook lolcats
I can haz cheezburger?

linecook doesn’t actually define way translate lines of text into lolcats, but you could easily define your own:

{
    'replacers': {
        'request': ['Can I', 'I can'],
        'verb': ['have', 'haz'],
        'noun': ['cheeseburger', 'cheezburger'],
    },
    'recipes': {
        'lolcats': ['request', 'verb', 'noun'],
    },
}

Recipes are just collections of transformations that translate a line of text into another line of text.

transforms:

A transform is the most generic type of transformation. It’s just a function that takes a string and returns an output string.

colorizers:

A colorizer is simply a transform that takes a substring match and wraps it with a terminal color.

replacers:

A replacer is a simple way to specify a transform that replaces a substring pattern with some output text.

deleters:

A deleter is simply a replacer where the output is an empty string.

filters:

A filter matches lines of text, which are skipped.

Obviously, this is an incredibly basic (and ridiculous) example. A more useful example colorizes lines of a log file using the following configuration:

{
    'colorizers': {
        'warn_color': {
            'match_pattern': ' WARN ',
            'color': 'yellow',
        },
        'error_color': {
            'match_pattern': ' ERROR ',
            'on_color': 'on_red',
        },
    },
    'recipes': {
        'logs': [
            'warn_color',
            'error_color',
        ],
    },
}

You can use the

$ tail -f path/to/log.txt | linecook logs

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

linecook-0.1.0.dev0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

linecook-0.1.0.dev0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file linecook-0.1.0.dev0.tar.gz.

File metadata

File hashes

Hashes for linecook-0.1.0.dev0.tar.gz
Algorithm Hash digest
SHA256 f0f26085c989fdf2dff2ea4d337e9246e6fb8c7e250fabe4fd33efce5bd05dca
MD5 2a4f8486c049c30ffb1b96f321967946
BLAKE2b-256 e2018b0110f205fb318b85fb659c76e69babf710811f3a246a5bcb34f1a4d954

See more details on using hashes here.

File details

Details for the file linecook-0.1.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for linecook-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 3763a732b5e444ad876c9737531e1ad33aecf5ecf29b296df833267f96da742c
MD5 0294e7ab2c65a632a0845a8afe58bfd1
BLAKE2b-256 753a33d35d34ba855db26d7d88922e8bc26745528ccc404090c96ec7309352ef

See more details on using hashes here.

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