stdio versus systemd

This commit is contained in:
deathbybandaid 2019-05-09 11:30:41 -04:00
parent a66f8f7c3e
commit 222acfb948
4 changed files with 41 additions and 17 deletions

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module
from sopel_modules.SpiceBot_Events.System import bot_events_recieved
from .Logs import errordisplay_fetch
from .Logs import systemd_logs_fetch
@sopel.module.event('2005')
@ -13,7 +13,7 @@ from .Logs import errordisplay_fetch
def bot_startup_monologue_start(bot, trigger):
bot_events_recieved(bot, trigger.event)
debuglines = errordisplay_fetch(bot)
debuglines = systemd_logs_fetch(bot)
searchphrasefound = []
for line in debuglines:

View File

@ -35,7 +35,7 @@ def setup(bot):
def bot_logs_setup_check(bot):
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []}
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []}
def shutdown(bot):
@ -66,18 +66,40 @@ def join_log_channel(bot, trigger):
return
def errordisplay_fetch(bot):
def stdio_logs_fetch(bot):
try:
log_file_lines = []
log_file = open("/home/sopel.sopel/logs/stdio.log", 'r')
lines = log_file.readlines()
for line in lines:
log_file_lines.append(line)
log_file.close()
currentline, linenumindex = 0, []
for line in log_file_lines:
if line.startswith("Welcome to Sopel. Loading modules..."):
linenumindex.append(currentline)
currentline += 1
last_start = max(linenumindex)
debuglines = log_file_lines[last_start:]
except Exception as e:
debuglines = e
debuglines = []
return debuglines
def systemd_logs_fetch(bot):
servicepid = get_running_pid(bot)
debuglines = []
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
if not str(line).startswith("-- Logs begin at"):
line = str(line).split(str(os.uname()[1] + " "))[-1]
if not str(line).startswith("sudo"):
lineparts = str(line).split(": ")
del lineparts[0]
line = spicemanip.main(lineparts, 0)
if not line.isspace():
debuglines.append(str(line))
line = str(line).split(str(os.uname()[1] + " "))[-1]
lineparts = str(line).split(": ")
del lineparts[0]
line = spicemanip.main(lineparts, 0)
if not line.isspace():
debuglines.append(str(line))
return debuglines

View File

@ -8,7 +8,7 @@ import spicemanip
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
from sopel_modules.SpiceBot_Events.System import bot_events_check
from .Logs import errordisplay_fetch
from .Logs import systemd_logs_fetch
@sopel.module.nickname_commands('logs', 'debug')
@ -30,10 +30,12 @@ def bot_command_action(bot, trigger):
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
if logtype != "Sopel_systemd":
logindex = bot.memory['SpiceBot_Logs']["logs"][logtype]
if logtype == "Sopel_systemd":
logindex = systemd_logs_fetch(bot)
elif logtype == "Sopel_stdio":
logindex = stdio_logs_fetch(bot)
else:
logindex = errordisplay_fetch(bot)
logindex = bot.memory['SpiceBot_Logs']["logs"][logtype]
if not len(logindex):
bot.osd("No logs found for " + str(logtype) + ".")

View File

@ -99,7 +99,7 @@ def command_permissions_check(bot, trigger, privslist):
def bot_logging(bot, logtype, logentry, stdio=False):
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []}
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []}
logmessage = "[" + logtype + "] " + logentry + ""