Metadata-Version: 2.1
Name: logargparser
Version: 0.1.0
Summary: 
Author: vengroff
Author-email: vengroff@gmail.com
Requires-Python: >=3.11,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Description-Content-Type: text/markdown

logargparser
------------

Utility for the common case of managing logs from the command line in simple utilities.

Sample usage
------------

In a python script called `sample.py`:

```python
import logging
from logargparser import LoggingArgumentParser
        
logger = logging.getLogger(__name__)
        
def main():
    # Instead of the normal `parser = argparse.ArgumentParser.
    parser = LoggingArgumentParser(logger)
        
    # Add as many other arguments as you want.
    parser.add_argument('-o', "--output")
        
    args = parser.parse_args()
        
    logger.info("The logger was set up for us based on --log and/or --logfile command line args.")
        
    if args.output is not None:
        # Do something....
        pass
        
        
if __name__ == "__main__":
    main()
```

We can then invoke the script from the command line.
First, to get help on all args:

```shell
python -m sample -h
```

The output will be: 

```
usage: sample.py [-h] [--log {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
                 [--logfile LOGFILE] [-o OUTPUT]

options:
  -h, --help            show this help message and exit
  --log {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Logging level.
  --logfile LOGFILE     Optional file path that logs should be appended to.
                        The file will be created if it does not exist.
  -o OUTPUT, --output OUTPUT
```

Notice that everything worked like a normal script using
`argparse.ArgParser`, but in addition to the `-o`/`--output`
argument we created ourselves, there are two other
arguments `--log` and `--logfile` available.

We can use `--log` as follows:

```shell
python -m sample --log INFO
```

This will produce the output

```
INFO:__main__:The logger was set up for us based on --log and/or --logfile command line args.
```

Notice that this output appears on the standard error
output. It is generated by the `logger.info` statement
in the python code above.

If we want this output to be appended to a log file
instead of being written to standard error, we can run

```shell
python -m sample --log INFO --logfile mylog.log
```

Now when we run it the output will go to the file we
specifcied, just as the help said it would.

