|
49 | 49 | )
|
50 | 50 | from core.thread import ThreadManager
|
51 | 51 | from core.time import human_timedelta
|
52 |
| -from core.utils import normalize_alias, parse_alias, truncate, tryint, human_join |
| 52 | +from core.utils import human_join, normalize_alias, parse_alias, truncate, tryint |
53 | 53 |
|
54 | 54 | logger = getLogger(__name__)
|
55 | 55 |
|
56 |
| - |
57 | 56 | temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
|
58 | 57 | if not os.path.exists(temp_dir):
|
59 | 58 | os.mkdir(temp_dir)
|
@@ -85,8 +84,11 @@ def __init__(self):
|
85 | 84 |
|
86 | 85 | self.threads = ThreadManager(self)
|
87 | 86 |
|
88 |
| - self.log_file_name = os.path.join(temp_dir, f"{self.token.split('.')[0]}.log") |
89 |
| - self._configure_logging() |
| 87 | + log_dir = os.path.join(temp_dir, "logs") |
| 88 | + if not os.path.exists(log_dir): |
| 89 | + os.mkdir(log_dir) |
| 90 | + self.log_file_path = os.path.join(log_dir, "modmail.log") |
| 91 | + configure_logging(self) |
90 | 92 |
|
91 | 93 | self.plugin_db = PluginDatabaseClient(self) # Deprecated
|
92 | 94 |
|
@@ -186,29 +188,6 @@ async def load_extensions(self):
|
186 | 188 | logger.exception("Failed to load %s.", cog)
|
187 | 189 | logger.line("debug")
|
188 | 190 |
|
189 |
| - def _configure_logging(self): |
190 |
| - level_text = self.config["log_level"].upper() |
191 |
| - logging_levels = { |
192 |
| - "CRITICAL": logging.CRITICAL, |
193 |
| - "ERROR": logging.ERROR, |
194 |
| - "WARNING": logging.WARNING, |
195 |
| - "INFO": logging.INFO, |
196 |
| - "DEBUG": logging.DEBUG, |
197 |
| - } |
198 |
| - logger.line() |
199 |
| - |
200 |
| - log_level = logging_levels.get(level_text) |
201 |
| - if log_level is None: |
202 |
| - log_level = self.config.remove("log_level") |
203 |
| - logger.warning("Invalid logging level set: %s.", level_text) |
204 |
| - logger.warning("Using default logging level: INFO.") |
205 |
| - else: |
206 |
| - logger.info("Logging level: %s", level_text) |
207 |
| - |
208 |
| - logger.info("Log file: %s", self.log_file_name) |
209 |
| - configure_logging(self.log_file_name, log_level) |
210 |
| - logger.debug("Successfully configured logging.") |
211 |
| - |
212 | 191 | @property
|
213 | 192 | def version(self):
|
214 | 193 | return parse_version(__version__)
|
@@ -1771,16 +1750,6 @@ def main():
|
1771 | 1750 | except ImportError:
|
1772 | 1751 | pass
|
1773 | 1752 |
|
1774 |
| - # Set up discord.py internal logging |
1775 |
| - if os.environ.get("LOG_DISCORD"): |
1776 |
| - logger.debug(f"Discord logging enabled: {os.environ['LOG_DISCORD'].upper()}") |
1777 |
| - d_logger = logging.getLogger("discord") |
1778 |
| - |
1779 |
| - d_logger.setLevel(os.environ["LOG_DISCORD"].upper()) |
1780 |
| - handler = logging.FileHandler(filename="discord.log", encoding="utf-8", mode="w") |
1781 |
| - handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) |
1782 |
| - d_logger.addHandler(handler) |
1783 |
| - |
1784 | 1753 | bot = ModmailBot()
|
1785 | 1754 | bot.run()
|
1786 | 1755 |
|
|
0 commit comments