mirror of
https://github.com/artiemis/artemis.git
synced 2026-02-14 08:31:55 +00:00
logging
This commit is contained in:
parent
57281a976d
commit
492cf7c384
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
temp/
|
temp/
|
||||||
env/
|
env/
|
||||||
*.log
|
|
||||||
config.prod.toml
|
config.prod.toml
|
||||||
config.dev.toml
|
config.dev.toml
|
||||||
status.json
|
status.json
|
||||||
@ -5,7 +5,6 @@ import contextlib
|
|||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from logging.handlers import RotatingFileHandler
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@ -18,13 +17,6 @@ if TYPE_CHECKING:
|
|||||||
from ..bot import Artemis
|
from ..bot import Artemis
|
||||||
|
|
||||||
log = logging.getLogger("artemis")
|
log = logging.getLogger("artemis")
|
||||||
cmd_log = logging.getLogger("commands")
|
|
||||||
cmd_log.propagate = False
|
|
||||||
cmd_log.setLevel(logging.DEBUG)
|
|
||||||
ch = RotatingFileHandler("data/commands.log", "a", 10 * 1024**2, encoding="utf-8")
|
|
||||||
ch.setLevel(logging.DEBUG)
|
|
||||||
ch.setFormatter(logging.Formatter("[{asctime}] {message}", "%Y-%m-%d %H:%M:%S", style="{"))
|
|
||||||
cmd_log.addHandler(ch)
|
|
||||||
|
|
||||||
TIKTOK_RE = re.compile(
|
TIKTOK_RE = re.compile(
|
||||||
r"https://vm\.tiktok\.com/(\w+)|https://(?:www\.)?tiktok\.com/(@.+?/video/\d+)"
|
r"https://vm\.tiktok\.com/(\w+)|https://(?:www\.)?tiktok\.com/(@.+?/video/\d+)"
|
||||||
@ -93,7 +85,7 @@ class Events(commands.Cog):
|
|||||||
|
|
||||||
content = message.content.lower()
|
content = message.content.lower()
|
||||||
if content.startswith(config.prefix) and f"{config.prefix}jsk" not in content:
|
if content.startswith(config.prefix) and f"{config.prefix}jsk" not in content:
|
||||||
cmd_log.debug(f"{message.author.id}: {message.content}")
|
log.info(f"[cmd] {message.author.id}: {message.content}")
|
||||||
|
|
||||||
await self.handle_triggers(message, content)
|
await self.handle_triggers(message, content)
|
||||||
await self.handle_links(message, content)
|
await self.handle_links(message, content)
|
||||||
|
|||||||
@ -180,31 +180,6 @@ except Exception:
|
|||||||
jsk_py = self.bot.get_command("jsk py")
|
jsk_py = self.bot.get_command("jsk py")
|
||||||
await jsk_py(ctx, argument=codeblocks.codeblock_converter(code))
|
await jsk_py(ctx, argument=codeblocks.codeblock_converter(code))
|
||||||
|
|
||||||
@dev.command()
|
|
||||||
async def logs(
|
|
||||||
self, ctx: commands.Context, app: Optional[str] = "bot", lines: Optional[int] = "50"
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Displays logs for various apps.
|
|
||||||
Available: bot, cmds, api, nginx
|
|
||||||
|
|
||||||
"""
|
|
||||||
match app:
|
|
||||||
case "bot":
|
|
||||||
args = f"tail -n {lines} artemis.log"
|
|
||||||
case "cmds":
|
|
||||||
args = f"tail -n {lines} data/commands.log"
|
|
||||||
case "api":
|
|
||||||
args = f"tail -n {lines} ../api/api.log"
|
|
||||||
case "nginx":
|
|
||||||
args = f"tail -n {lines} /var/log/nginx/access.log"
|
|
||||||
case _:
|
|
||||||
return await ctx.send("Unrecognized app.")
|
|
||||||
|
|
||||||
ext = "py" if app == "bot" else "txt"
|
|
||||||
file = await utils.run_cmd_to_file(args, f"{app}-logs_{utils.time()}.{ext}")
|
|
||||||
return await ctx.reply(file=file)
|
|
||||||
|
|
||||||
@dev.command()
|
@dev.command()
|
||||||
async def http(self, ctx: commands.Context, url: str):
|
async def http(self, ctx: commands.Context, url: str):
|
||||||
"""Debugs HTTP requests."""
|
"""Debugs HTTP requests."""
|
||||||
|
|||||||
@ -4,9 +4,6 @@ module.exports = {
|
|||||||
name: "artemis",
|
name: "artemis",
|
||||||
script: "./env/bin/python",
|
script: "./env/bin/python",
|
||||||
args: "-m artemis.bot",
|
args: "-m artemis.bot",
|
||||||
out_file: "/dev/null",
|
|
||||||
error_file: "/dev/null",
|
|
||||||
log_file: "./artemis.log",
|
|
||||||
time: true,
|
time: true,
|
||||||
env: {
|
env: {
|
||||||
PYTHONUNBUFFERED: "1",
|
PYTHONUNBUFFERED: "1",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user