Skip to main content

A utility for managing logging directories.

Project description

LogDir

A utility for managing logging directories.

Source PyPI CI/CD Docs Docs Status
GitHub PyPI Test and Deploy logdir.btjanaka.net Netlify Status

Installation

To install from PyPI, run:

pip install logdir

To install from Conda, run:

conda install -c conda-forge logdir

To install from source, clone this repo, cd into it, and run:

pip install .

logdir is tested on Python 3.7+. Earlier Python versions may work but are not guaranteed.

Usage

If your experiment is called My Experiment, you can create a logging directory for it with:

from logdir import LogDir

logdir = LogDir("My Experiment")

This will create a logging directory of the form ./logs/YYYY-MM-DD_HH-MM-SS_my-experiment-dir; you can change ./logs by passing in a second argument for the root directory when initializing LogDir, i.e. LogDir("My Experiment", "./different-log-dir").

You now have access to useful methods for creating files and saving data in the directory. For example, start writing to a file new.txt in the directory with:

with logdir.pfile("new.txt").open() as file:
    file.write("Hello World!")

This takes advantage of the pfile() method, which creates a pathlib.Path to the new file. It also uses pathlib.Path.open().

pfile() will also create intermediate directories, so this will work even if foo/bar/ does not exist in the logging directory already:

with logdir.pfile("foo/bar/new.txt").open() as file:
    file.write("Hello World!")

There is also save_data(), which saves data to a file. JSON, YAML, TOML, and pickle files are currently supported.

logdir.save_data({"a": 1, "b": 2, "c": 3}, "file.json")

Finally, readme() adds a README.md to the directory with multiple pieces of information. For instance, this command:

logdir.readme(date=True, git_commit=True)

Will create something like:

# My Experiment

- Date: 2020-10-04 23:04:05
- Git Commit: e3rftyt543rt5y67jhtgr4yhju

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

logdir-0.9.3.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logdir-0.9.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file logdir-0.9.3.tar.gz.

File metadata

  • Download URL: logdir-0.9.3.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.10 Linux/5.4.0-1039-azure

File hashes

Hashes for logdir-0.9.3.tar.gz
Algorithm Hash digest
SHA256 b4d08e4b481f19bb043a8cfba6bdc3ad6e3c2612a4343b060d9cdf7279177122
MD5 01b773d7ba251804fe0676e4f360588e
BLAKE2b-256 11063fc8953f3812365c2f02b1a52798ac8005696569d1c56b12724d89916533

See more details on using hashes here.

File details

Details for the file logdir-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: logdir-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.10 Linux/5.4.0-1039-azure

File hashes

Hashes for logdir-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b0edddb34d61ab2a8e9d858b7606fe13c1f4dcbe49997a0618f7a0fa24e34236
MD5 8458fa06a85d92d98804e963c105a6ff
BLAKE2b-256 c297d3ce61d03844765ffe41fd4058f7d3f6612c889690fd7f83021211bb8489

See more details on using hashes here.

Supported by

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