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 oferror
,warn
,info
, ordebug
; 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
Release history Release notifications | RSS feed
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.2.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file basecmd-0.1.2.tar.gz
.
File metadata
- Download URL: basecmd-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 544b7ef9768813b63ef27ef3c8e0c52f98c5fd7049b57a1b4bbed12d2256a51e |
|
MD5 | e188dcb0a2da190ef5b352f61d53c8b3 |
|
BLAKE2b-256 | 7a1b0043ce7c1bf610cc3e1e23a685a93247d1f93440d171241175579734a4af |
File details
Details for the file basecmd-0.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: basecmd-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85bd4a316db04a46b3ae1340812dac2612e1bb57be923ce43cde0b185180632c |
|
MD5 | 6428ce42fe5649452415b34c39596c1d |
|
BLAKE2b-256 | 3d2fee05abd5c02a0532409b1f5b93fed41b35e0ce217ed851d2c80892fb0e97 |