Skip to main content

Logging boilerplate for the command line

Project description

basecmd

Boilerplate for the command line.

Classes inheriting from BaseCmd have a self.log attribute that is a standard Python logger. A basic logging configuration to sys.stdout is provided.

For command line options controlling the logging verbosity and output to a log file, call the command with -h or --help.

Defaults for logging options can be also provided as environment variables or in a .emv file:

  • LOG_LEVEL: the logging verbosity, one of error, warn, info, or debug; default: info. ' LOG_FILE: path to a log file, defaults to the standard output for easy redirection.
  • LOG_FORMAT: a standard Python logging format, defaults to %(asctime).19s %(message)s when logging to a file or a terminal and %(message)s otherwise.

When logging to a terminal, the output is colored by log level.

Example usage

from basecmd import BaseCmd

class MyCmd(BaseCmd):

    def add_arguments(self):
        self.parser.add_argument('--foo',
            help='Custom command line option')

    def __call__(self):
        self.log.debug(self.options.foo)

if __name__ == '__main__':
    cmd = MyCmd
    cmd()

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

basecmd-0.1.8.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

basecmd-0.1.8-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file basecmd-0.1.8.tar.gz.

File metadata

  • Download URL: basecmd-0.1.8.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for basecmd-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3fc86bcccfa85e620723adcbdfb994e81514d44b7bd5a6fb69aae0807f6cfb9a
MD5 1a74da370f0adc97f0303362bcbf023d
BLAKE2b-256 3f08f3f94df98810aa5139c3353f93e1f91f82f95e629549f79476d587a640cd

See more details on using hashes here.

File details

Details for the file basecmd-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: basecmd-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for basecmd-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 76e7d3981ac8814004a76ebd1516d52a603e730989f8d533a5e9307a32716f46
MD5 d0089a156aa1b3b3c0c18e5f4933f729
BLAKE2b-256 3f303b61d329f4e0596a8959bf1e3ceee945030f614f09dfbfaf4e993c6a2e3e

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