Repository: opsdroid/opsdroid

Issue:
Opsdroid logger returning errors
# Description
Hi, I have been using `opsdroid` for a few days now, and while it is a good framework, I have been having a lot of trouble. Most recently I have been getting a error `formatter refrenced before use`. I have linted my configuration.yaml and none of my python files have errors. The error message below only shows errors in opsdroid library files. Even so, I am probably doing something wrong. Any help is greatly appreciated!

## Steps to Reproduce
I just linted and built my config. Neither of those actions returned errors.

## Expected Functionality
My bot should have run on Telegram and in bash.

## Experienced Functionality
```bash
Traceback (most recent call last):
  File "/home/gideongrinberg/.local/bin/opsdroid", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/gideongrinberg/.local/lib/python3.6/site-packages/opsdroid/cli/start.py", line 38, in start
    configure_logging(config)
  File "/home/gideongrinberg/.local/lib/python3.6/site-packages/opsdroid/logging.py", line 93, in configure_logging
    console_handler.setFormatter(formatter)
UnboundLocalError: local variable 'formatter' referenced before assignment
```
## Versions
- **Opsdroid version:** 0.17.1
- **Python version:** Python 3.6.9
- **OS/Docker version:** Ubuntu 18.04 on Window Subsystem Linux (Windows 10)

## Configuration File
My config.yaml is to large to include, but this is the only line I've change from the example (other than adding tokens)
```yaml

  recycle-nlp:
    path: '~/opdroid_recycle/skill-recycle-nlp'
```
Again, that file returns no errors when I run `opsdroid config -f [PATH] lint` or `opsdroid config -f [PATH] build`.

Additionally, the python file:
```python
from opsdroid.skill import Skill
from opsdroid.matchers import match_luisai_intent

class recycle-nlp(Skill):
@match_luisai_intent('recycle')
    async def recycle-nlp(self, message):
        if message.luisai["topScoringIntent"]["intent"]=="recycle":
            await message.respond(str(message.luisai))
```
My directory structure (/home for WSL, not windows):
```
| /home
            |____ opsdroid_recycle
                           |
                           |_____ config.yaml
                           |_____skill-recycle-nlp
                                               |
                                               |____ __init__.py
                                                |______ README.md
                                                |______ LICENSE
           |
           |___.local/lib/python3.6/site-packages
```
## Additional Details
Interestingly, my bot worked fine with the example config

Any help is much appreciated! 



Discussion:
I've hit the same error, when enabling logging as defined in the default configuration sourced from https://raw.githubusercontent.com/opsdroid/opsdroid/master/opsdroid/configuration/example_configuration.yaml.

The block that triggers the error is:
```yaml
logging:
  level: info
  path: opsdroid.log
  console: true
  extended: false
  filter:
    whitelist:
      - opsdroid.core
    blacklist:
      - opsdroid.loader
```

The error message is as follows
```python
opsdroid start -f /opt/opsdroid/configuration.yaml 
Traceback (most recent call last):
  File "/opt/opsdroid/bin/opsdroid", line 8, in <module>
    sys.exit(cli())
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/opt/opsdroid/lib/python3.7/site-packages/opsdroid/cli/start.py", line 38, in start
    configure_logging(config)
  File "/opt/opsdroid/lib/python3.7/site-packages/opsdroid/logging.py", line 93, in configure_logging
    console_handler.setFormatter(formatter)
UnboundLocalError: local variable 'formatter' referenced before assignment
```

Version
```
pip freeze | grep opsdroid
opsdroid==0.17.1
```
@nzlosh where you able to fix this? Did you try `opsdroid config -f [PATH] lint`?
@nzlosh this issue appears to be logging related.  The `formatter` is defined in [logging.py](https://github.com/opsdroid/opsdroid/blob/7f817f61a6d4042b4bd930e4aca15b3387786cd0/opsdroid/logging.py). @FabioRosado appears to have worked on that file most recently, so maybe he can shed some light on how to fix this. 
Hello @Gideon357  and @nzlosh  Thank you for raising this issue and I'd like to apologise for the troubles you are having with opsdroid. 

Just out of curiosity are you setting your logging with the `extended` set to false and do you have any `whitelist` or `blacklist` filter set to it? 

I might have botched up something while creating the extended filter. I'm going to work on this issue tomorrow and hopefully fix it.

@FabioRosado thanks for responding. I was using the default configuration that I generated using `opsdroid config gen > config.yaml`. If you need help fixing it, let me know. I do know @nzlosh had his logging setup like this:

```yaml
logging:
  level: info
  path: opsdroid.log
  console: true
  extended: false
  filter:
    whitelist:
      - opsdroid.core
    blacklist:
      - opsdroid.loader
```


Resolving patch:
diff --git a/opsdroid/logging.py b/opsdroid/logging.py
--- a/opsdroid/logging.py
+++ b/opsdroid/logging.py
@@ -83,13 +83,13 @@ def configure_logging(config):
 
     rootlogger.setLevel(log_level)
 
-    try:
+    formatter = logging.Formatter("%(levelname)s %(name)s: %(message)s")
+
+    with contextlib.suppress(KeyError):
         if config["logging"]["extended"]:
             formatter = logging.Formatter(
                 "%(levelname)s %(name)s.%(funcName)s(): %(message)s"
             )
-    except KeyError:
-        formatter = logging.Formatter("%(levelname)s %(name)s: %(message)s")
 
     console_handler = logging.StreamHandler()
     console_handler.setLevel(log_level)


Test patch: