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.5.tar.gz (3.9 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.5-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: basecmd-0.1.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for basecmd-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9f6ae23e97f3c7a2c1d90c49ca664772ae35295e381746ad60f4ee01820e5823
MD5 2256fbe79ed855db18d2d60cf1a9bd6e
BLAKE2b-256 955396590b7ddfc093c601fb40724211f2d1954f7339859c906f83507b5a79c2

See more details on using hashes here.

File details

Details for the file basecmd-0.1.5-py2.py3-none-any.whl.

File metadata

  • Download URL: basecmd-0.1.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for basecmd-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8469695e621d10e825d55a8486c5a8691a62305901ba2f2f970096bbd54a6073
MD5 391748df3fd83c44629f627ff4b9f39a
BLAKE2b-256 5a434eadf68f06e44b6a071b89e360a518099548c634de1acdd923fad3d7301f

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