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.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for basecmd-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31ebf192e83d340946d114b10ea4fa23eb09adac0e93c480e0ea01e182571ed9 |
|
MD5 | b0a2cbe5182bca467a6f9d13925f745c |
|
BLAKE2b-256 | 2b6c9cefaa6d3f1be4d65963f6bee832a46bf952688cbceba3b0fc51980c8d34 |