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

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: basecmd-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 2e11e535d695d45d061f0b2f71daafc05b36b12ca1bab142a523eaf5a633bc80
MD5 eeb77ee154c149a830d3cf3cb7a4cebe
BLAKE2b-256 b937f277beedbe8c841990913dbde9f0e8fd5de1009e56d515b66dea6fc45914

See more details on using hashes here.

File details

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

File metadata

  • Download URL: basecmd-0.1.4-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.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f09da64e26532453dff766f5b1b8e75924bc9614f9d87aad3148ab68c5131ae3
MD5 d2bf4f758f0afb81764755ebb6b91c8d
BLAKE2b-256 aed677d3262e81949fabbdef322df0cb36bf8d17d53dc5b99786bb7a3c3fc146

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