Fix the HF logger
Author: jplu
Pull request: yes

Hello.

The current HF logger do not behave as expected. As example let's take the `run_tf_ner.py` script. With the following header:

```
import logging
import os
from dataclasses import dataclass, field
from importlib import import_module
from typing import Dict, List, Optional, Tuple

import numpy as np
from seqeval.metrics import classification_report, f1_score, precision_score, recall_score

from transformers import logging as hf_logging

handler = logging.StreamHandler()
formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s')
handler.setFormatter(formatter)

logger = hf_logging.get_logger(__name__)

logger.handlers.clear()
logger.addHandler(handler)
hf_logging.enable_propagation()
hf_logging.set_verbosity_info()
hf_logging.enable_default_handler()

from transformers import (
    AutoConfig,
    AutoTokenizer,
    EvalPrediction,
    HfArgumentParser,
    TFAutoModelForTokenClassification,
    TFTrainer,
    TFTrainingArguments,
)
from utils_ner import Split, TFTokenClassificationDataset, TokenClassificationTask
```

The formatter is fully ignored and takes the default logging format of TensorFlow.

This PR fixes the problem with the following new header:
```
import logging
import os
from dataclasses import dataclass, field
from importlib import import_module
from typing import Dict, List, Optional, Tuple

import numpy as np
from seqeval.metrics import classification_report, f1_score, precision_score, recall_score
import tensorflow as tf

from transformers import logging as hf_logging

handler = logging.StreamHandler()
formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s')
handler.setFormatter(formatter)

logger = hf_logging.get_logger()

logger.handlers.clear()
logger.addHandler(handler)
logger.setLevel(logging.INFO)

from transformers import (
    AutoConfig,
    AutoTokenizer,
    EvalPrediction,
    HfArgumentParser,
    TFAutoModelForTokenClassification,
    TFTrainer,
    TFTrainingArguments,
)
from utils_ner import Split, TFTokenClassificationDataset, TokenClassificationTask
```

But now the logger is set at library level and not at the class level anymore.

Then I wanted to know if this slitght update is a problem or if it is ok. 

Comments:
I think the issue stems from the fact that this example is not relying on the base `transformers` logging. The logger is defined by the `__name__` from which you initialize it, and when you're initializing the logger within `transformers` you're doing the following:

```py
# file_utils.py
file_utils_logger = logging.get_logger(__name__)  # initializes the logger with `transformers.file_utils`
```

```py
# modeling_utils.py
modeling_utils_logger = logging.get_logger(__name__)  # initializes the logger with `transformers.modeling_utils`
```

Therefore when you're getting the base `transformers` logger and changing its level, you're also changing all these loggers' levels.

```py
file_utils_logger.getEffectiveLevel()  # 30
modeling_utils_logger.getEffectiveLevel()  # 30

logger = logging.get_logger()
logger.setLevel(logging.INFO)

file_utils_logger.getEffectiveLevel()  # 20
modeling_utils_logger.getEffectiveLevel()  # 20
```

However, for the `run_tf_ner.py` script, the `__name__` is not dependent on `transformers.[module_name]`, but is instead `__main__`. When you're updating the root HF logger's level, it's therefore not updating that logger level. You can run the following script to see what happens:

```py
from transformers import logging

file_utils_logger = logging.get_logger('transformers.file_utils')
modeling_utils_logger = logging.get_logger('transformers.modeling_utils')
ner_script = logging.get_logger('__main__')

print(file_utils_logger.getEffectiveLevel(), modeling_utils_logger.getEffectiveLevel(), ner_script.getEffectiveLevel())
# 30 30 30

main = logging.get_logger()
main.setLevel(logging.INFO)

print(file_utils_logger.getEffectiveLevel(), modeling_utils_logger.getEffectiveLevel(), ner_script.getEffectiveLevel())
# 20 20 30
```

I think the same thing is happening with handlers. What do you think?

You are totally right. I fully reverted the changes in `logging.py` and replaced all the missing usage of the HF wrapper in the lib.

# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=h1) Report
> Merging [#7128](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/52d250f6aa14844024806e5e4dd1c7882bbd8dd5?el=desc) will **increase** coverage by `1.73%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/7128/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #7128      +/-   ##
==========================================
+ Coverage   79.12%   80.86%   +1.73%     
==========================================
  Files         168      168              
  Lines       32303    32303              
==========================================
+ Hits        25560    26121     +561     
+ Misses       6743     6182     -561     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/configuration\_lxmert.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX2x4bWVydC5weQ==) | `100.00% <100.00%> (ø)` | |
| [src/transformers/modeling\_lxmert.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19seG1lcnQucHk=) | `90.76% <100.00%> (+20.74%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_lxmert.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9seG1lcnQucHk=) | `94.11% <100.00%> (ø)` | |
| [src/transformers/modeling\_tf\_funnel.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9mdW5uZWwucHk=) | `18.53% <0.00%> (-75.51%)` | :arrow_down: |
| [src/transformers/modeling\_marian.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19tYXJpYW4ucHk=) | `60.00% <0.00%> (-30.00%)` | :arrow_down: |
| [src/transformers/activations.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9hY3RpdmF0aW9ucy5weQ==) | `85.00% <0.00%> (-5.00%)` | :arrow_down: |
| [src/transformers/modeling\_bart.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19iYXJ0LnB5) | `93.77% <0.00%> (-0.51%)` | :arrow_down: |
| [src/transformers/tokenization\_utils\_base.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fdXRpbHNfYmFzZS5weQ==) | `93.64% <0.00%> (-0.41%)` | :arrow_down: |
| [src/transformers/modeling\_tf\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9iZXJ0LnB5) | `98.38% <0.00%> (-0.36%)` | :arrow_down: |
| [src/transformers/file\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9maWxlX3V0aWxzLnB5) | `82.84% <0.00%> (-0.25%)` | :arrow_down: |
| ... and [17 more](https://codecov.io/gh/huggingface/transformers/pull/7128/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=footer). Last update [52d250f...977b295](https://codecov.io/gh/huggingface/transformers/pull/7128?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


It should be ok from my side. @LysandreJik you can review whenever you want.