Repository: scikit-hep/pyhf

Issue:
Logging configuration in contrib/utils
# Question

`pyhf.contrib.utils` sets up logging:
https://github.com/scikit-hep/pyhf/blob/6b769fd6f5e1473deba2b4c55d49ebdb3db5b447/src/pyhf/contrib/utils.py#L9 

This interferes with custom logging users may want to set up. To achieve this now, they would have to do so before `from pyhf.contrib.utils import download`. To avoid this issue, the logging should not be configured in this part of the code (and only for the CLI).

# Relevant Issues and Pull Requests

#865

User-defined log formatting
# Description

`pyhf` uses `logging` for outputs, and calls `logging.basicConfig()` in a few places.
This has the effect of preventing the user to set their desired logging behavior after `pyhf` import.
While calling this a bug might be a bit of a stretch, I think it might be unintentional since `pyhf` does not apply any logging formatting as far as I can tell.

# Expected Behavior

I expect no calls to `logging.basicConfig()` within `pyhf` to leave the formatting fully up to the user, no matter whether they want to set it before or after importing `pyhf`.

# Actual Behavior

User-defined `logging` formatting only works before importing `pyhf`.

# Steps to Reproduce

importing `pyhf` before formatting:
```
import logging
import pyhf
print(pyhf.__version__)
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
log.info("message")
```
output:
```
0.4.1
```
and when applying formatting before input, the expected behavior:
```
import logging
logging.basicConfig(level=logging.INFO)
import pyhf
print(pyhf.__version__)
log = logging.getLogger(__name__)
log.info("message")
```
output:
```
0.4.1
INFO:__main__:message
``` 

# Checklist

- [ ] Run `git fetch` to get the most up to date version of `master`
  - no, but checked code on master to confirm that the relevant part is unchanged
- [X] Searched through existing Issues to confirm this is not a duplicate issue
- [X] Filled out the Description, Expected Behavior, Actual Behavior, and Steps to Reproduce sections above or have edited/removed them in a way that fully describes the issue



Discussion:
I would consider this a bug.. logging shoulld only ever be setup in the "CLI" modules that serce as non-library entryopints. Thanks!
Thanks for reporting this @alexander-held. I think this is something that would be reasonable for us to look into, maybe for a quick `v0.5.1` patch release once we finish shepherding `v0.5.0` out.
`logging.basicConfig` should only be called in `commandline.py`
@alexander-held as @lukasheinrich took at look at this and was super speedy about this it will go into the next patch release `v0.4.2` which should be out soon (O(<1 week)). You and I have talked about how to install dev versions of `pyhf` though so as soon as PR #866 is in you can start using it in the interim.
Thanks a lot for taking care of this!

Resolving patch:
diff --git a/src/pyhf/contrib/utils.py b/src/pyhf/contrib/utils.py
--- a/src/pyhf/contrib/utils.py
+++ b/src/pyhf/contrib/utils.py
@@ -6,7 +6,6 @@
 import logging
 from .. import exceptions
 
-logging.basicConfig()
 log = logging.getLogger(__name__)
 
 __all__ = ["download"]


Test patch: