|
1 | 1 | import logging |
2 | 2 | import os |
3 | 3 | import asyncio |
4 | | -import subprocess |
5 | | -import sys |
6 | 4 |
|
7 | 5 | from dotenv import load_dotenv |
8 | 6 | from bot.bot import main, config |
9 | 7 |
|
| 8 | +logging_data = config.get('logging') |
| 9 | +load_dotenv() |
10 | 10 |
|
11 | | -if logging_data := config.get('logging'): |
| 11 | +if __name__ == '__main__': |
12 | 12 | if logging_level := logging_data.get('level'): |
13 | 13 | if logging_level and logging_level not in ( |
14 | 14 | 'error', |
|
18 | 18 | ): |
19 | 19 | logging_level = 'info' |
20 | 20 |
|
21 | | - if logging_filename := logging_data.get('filename'): |
22 | | - if not logging_filename.endswith('.log'): |
23 | | - logging_filename = logging_filename + '.log' |
24 | | - |
25 | | - logging_console: bool = logging_data.get('console', False) |
26 | | - |
27 | | - logging.basicConfig(level=getattr(logging, logging_level.upper()), filename=logging_filename) |
28 | | - if logging_console: |
29 | | - logging.getLogger().addHandler(logging.StreamHandler()) |
| 21 | + if logging_filename := logging_data.get('filename'): |
| 22 | + if not logging_filename.endswith('.log'): |
| 23 | + logging_filename = logging_filename + '.log' |
30 | 24 |
|
31 | | - if not logging_console and not logging_filename: |
32 | | - print(''' |
33 | | - You have enabled logging but set left both console and filename blank. |
34 | | - Nothing will be printed to the console or written to a file. |
35 | | - ''') |
| 25 | + if logging_data.get('console', False): |
| 26 | + logging.getLogger().addHandler(logging.StreamHandler()) |
| 27 | + elif not logging_filename: |
| 28 | + print(''' |
| 29 | + You have enabled logging but set left both console and filename blank. |
| 30 | + Nothing will be printed to the console or written to a file. |
| 31 | + ''') |
36 | 32 |
|
37 | | -load_dotenv() |
38 | | - |
39 | | -if __name__ == '__main__': |
40 | | - if config.get('auto_updates', False): |
41 | | - pull = str(subprocess.check_output(['git', 'pull']), 'UTF-8') |
42 | | - if 'up to date' not in pull: |
43 | | - logging.info('Auto-update has installed the latest version. Restarting...') |
44 | | - os.execv(sys.executable, ['python'] + sys.argv) |
| 33 | + logging.basicConfig(level=getattr(logging, logging_level.upper()), filename=logging_filename) |
45 | 34 |
|
46 | 35 | if TOKEN := os.environ.get('TOKEN'): |
47 | 36 | logging.info('Starting bot') |
|
0 commit comments