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.0.0.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.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: basecmd-0.0.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for basecmd-0.0.0.tar.gz
Algorithm Hash digest
SHA256 58ed46bb138c49923bf7cf12772b9e7b0bcff710fc92576ee430f6f9668965b1
MD5 c4159e5974c88b45c07a4ce8e7d17583
BLAKE2b-256 b4e41122abd44fc78fbbbc412630f19f3f008179b5d1d2f0dc5842826a19d9e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: basecmd-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for basecmd-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f560080db953a2b45c2c0e0ad5a68adc4926a089c8b889f15380451a3cb4195
MD5 84112a62a6f06acbdac53f73f41f115b
BLAKE2b-256 d2df89ba86cfc6f9513f8459b33b31b85843e8e838ffc5cd80f00aaa64fa89a3

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