Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnknth/basecmd
Logging boilerplate for command line programs in Python
https://github.com/dnknth/basecmd
command-line logging python3
Last synced: 29 days ago
JSON representation
Logging boilerplate for command line programs in Python
- Host: GitHub
- URL: https://github.com/dnknth/basecmd
- Owner: dnknth
- License: mit
- Created: 2022-07-08T13:33:45.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T16:36:30.000Z (5 months ago)
- Last Synced: 2024-11-05T06:25:01.378Z (about 2 months ago)
- Topics: command-line, logging, python3
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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
```python
from basecmd import BaseCmdclass 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()
```