mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 15:09:54 -05:00
logs without bot
This commit is contained in:
parent
3c5608f347
commit
ae8e58b819
@ -11,6 +11,8 @@ import threading
|
|||||||
import os
|
import os
|
||||||
import spicemanip
|
import spicemanip
|
||||||
|
|
||||||
|
from .Config import config as botconfig
|
||||||
|
|
||||||
|
|
||||||
class BotLogs():
|
class BotLogs():
|
||||||
"""This Is a contained source of log information"""
|
"""This Is a contained source of log information"""
|
||||||
@ -20,9 +22,6 @@ class BotLogs():
|
|||||||
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
||||||
"queue": []
|
"queue": []
|
||||||
}
|
}
|
||||||
self.sopel_config = {
|
|
||||||
"logging_channel": True
|
|
||||||
}
|
|
||||||
|
|
||||||
def log(self, logtype, logentry, stdio=False):
|
def log(self, logtype, logentry, stdio=False):
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ class BotLogs():
|
|||||||
logtitle = "[" + logtype + "]"
|
logtitle = "[" + logtype + "]"
|
||||||
logmessage = logtitle + " " + logentry
|
logmessage = logtitle + " " + logentry
|
||||||
|
|
||||||
if self.sopel_config["logging_channel"]:
|
if botconfig.config.core.logging_channel:
|
||||||
self.dict["queue"].append(logmessage)
|
self.dict["queue"].append(logmessage)
|
||||||
|
|
||||||
if stdio:
|
if stdio:
|
||||||
@ -43,22 +42,22 @@ class BotLogs():
|
|||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def get_logs(self, bot, logtype):
|
def get_logs(self, logtype):
|
||||||
if logtype == "Sopel_systemd":
|
if logtype == "Sopel_systemd":
|
||||||
logindex = self.systemd_logs_fetch(bot)
|
logindex = self.systemd_logs_fetch()
|
||||||
elif logtype == "Sopel_stdio":
|
elif logtype == "Sopel_stdio":
|
||||||
logindex = self.stdio_logs_fetch(bot)
|
logindex = self.stdio_logs_fetch()
|
||||||
else:
|
else:
|
||||||
logindex = self.dict["list"][logtype]
|
logindex = self.dict["list"][logtype]
|
||||||
return logindex
|
return logindex
|
||||||
|
|
||||||
def stdio_logs_fetch(self, bot):
|
def stdio_logs_fetch(self):
|
||||||
|
|
||||||
stdio_ignore = []
|
stdio_ignore = []
|
||||||
for logtype in self.dict["list"].keys():
|
for logtype in self.dict["list"].keys():
|
||||||
stdio_ignore.append("[" + logtype + "]")
|
stdio_ignore.append("[" + logtype + "]")
|
||||||
|
|
||||||
logfile = os.path.os.path.join(bot.config.core.logdir, 'stdio.log')
|
logfile = os.path.os.path.join(botconfig.config.core.logdir, 'stdio.log')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log_file_lines = []
|
log_file_lines = []
|
||||||
@ -92,8 +91,8 @@ class BotLogs():
|
|||||||
|
|
||||||
return debuglines
|
return debuglines
|
||||||
|
|
||||||
def systemd_logs_fetch(self, bot):
|
def systemd_logs_fetch(self):
|
||||||
servicepid = self.get_running_pid(bot)
|
servicepid = self.get_running_pid()
|
||||||
debuglines = []
|
debuglines = []
|
||||||
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
|
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
|
||||||
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
||||||
@ -104,14 +103,14 @@ class BotLogs():
|
|||||||
debuglines.append(str(line))
|
debuglines.append(str(line))
|
||||||
return debuglines
|
return debuglines
|
||||||
|
|
||||||
def get_running_pid(self, bot):
|
def get_running_pid(self):
|
||||||
try:
|
try:
|
||||||
filename = "/run/sopel/sopel-" + str(bot.nick) + ".pid"
|
filename = "/run/sopel/sopel-" + str(botconfig.config.core.nick) + ".pid"
|
||||||
with open(filename, 'r') as pid_file:
|
with open(filename, 'r') as pid_file:
|
||||||
pidnum = int(pid_file.read())
|
pidnum = int(pid_file.read())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pidnum = e
|
pidnum = e
|
||||||
pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
|
pidnum = str(os.popen("systemctl show " + str(botconfig.config.core.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||||
return pidnum
|
return pidnum
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ def bot_command_logs(bot, trigger):
|
|||||||
|
|
||||||
logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys())
|
logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys())
|
||||||
|
|
||||||
logindex = SpiceBot.logs.get_logs(bot, logtype)
|
logindex = SpiceBot.logs.get_logs(logtype)
|
||||||
|
|
||||||
if not len(logindex):
|
if not len(logindex):
|
||||||
bot.osd("No logs found for " + str(logtype) + ".")
|
bot.osd("No logs found for " + str(logtype) + ".")
|
||||||
|
|||||||
@ -18,7 +18,7 @@ def setup(bot):
|
|||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def join_log_channel(bot, trigger):
|
def join_log_channel(bot, trigger):
|
||||||
|
|
||||||
if bot.config.core.logging_channel:
|
if SpiceBot.config.config.core.logging_channel:
|
||||||
channel = bot.config.core.logging_channel
|
channel = bot.config.core.logging_channel
|
||||||
if channel not in bot.channels.keys():
|
if channel not in bot.channels.keys():
|
||||||
bot.write(('JOIN', bot.nick, channel))
|
bot.write(('JOIN', bot.nick, channel))
|
||||||
@ -30,5 +30,4 @@ def join_log_channel(bot, trigger):
|
|||||||
bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel)
|
bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel)
|
||||||
del SpiceBot.logs.dict["queue"][0]
|
del SpiceBot.logs.dict["queue"][0]
|
||||||
else:
|
else:
|
||||||
SpiceBot.logs.sopel_config["logging_channel"] = False
|
|
||||||
SpiceBot.logs.dict["queue"] = []
|
SpiceBot.logs.dict["queue"] = []
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import sopel_modules.SpiceBot as SpiceBot
|
|||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_startup_monologue_start(bot, trigger):
|
def bot_startup_monologue_start(bot, trigger):
|
||||||
|
|
||||||
debuglines = SpiceBot.logs.stdio_logs_fetch(bot)
|
debuglines = SpiceBot.logs.stdio_logs_fetch()
|
||||||
|
|
||||||
searchphrasefound = []
|
searchphrasefound = []
|
||||||
for line in debuglines:
|
for line in debuglines:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user