mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
stdio versus systemd
This commit is contained in:
parent
a66f8f7c3e
commit
222acfb948
@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
import sopel.module
|
import sopel.module
|
||||||
|
|
||||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved
|
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')
|
@sopel.module.event('2005')
|
||||||
@ -13,7 +13,7 @@ from .Logs import errordisplay_fetch
|
|||||||
def bot_startup_monologue_start(bot, trigger):
|
def bot_startup_monologue_start(bot, trigger):
|
||||||
bot_events_recieved(bot, trigger.event)
|
bot_events_recieved(bot, trigger.event)
|
||||||
|
|
||||||
debuglines = errordisplay_fetch(bot)
|
debuglines = systemd_logs_fetch(bot)
|
||||||
|
|
||||||
searchphrasefound = []
|
searchphrasefound = []
|
||||||
for line in debuglines:
|
for line in debuglines:
|
||||||
|
|||||||
@ -35,7 +35,7 @@ def setup(bot):
|
|||||||
|
|
||||||
def bot_logs_setup_check(bot):
|
def bot_logs_setup_check(bot):
|
||||||
if 'SpiceBot_Logs' not in bot.memory:
|
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):
|
def shutdown(bot):
|
||||||
@ -66,13 +66,35 @@ def join_log_channel(bot, trigger):
|
|||||||
return
|
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)
|
servicepid = get_running_pid(bot)
|
||||||
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'):
|
||||||
if not str(line).startswith("-- Logs begin at"):
|
|
||||||
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
||||||
if not str(line).startswith("sudo"):
|
|
||||||
lineparts = str(line).split(": ")
|
lineparts = str(line).split(": ")
|
||||||
del lineparts[0]
|
del lineparts[0]
|
||||||
line = spicemanip.main(lineparts, 0)
|
line = spicemanip.main(lineparts, 0)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import spicemanip
|
|||||||
|
|
||||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
|
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 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')
|
@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())
|
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
|
||||||
|
|
||||||
if logtype != "Sopel_systemd":
|
if logtype == "Sopel_systemd":
|
||||||
logindex = bot.memory['SpiceBot_Logs']["logs"][logtype]
|
logindex = systemd_logs_fetch(bot)
|
||||||
|
elif logtype == "Sopel_stdio":
|
||||||
|
logindex = stdio_logs_fetch(bot)
|
||||||
else:
|
else:
|
||||||
logindex = errordisplay_fetch(bot)
|
logindex = bot.memory['SpiceBot_Logs']["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) + ".")
|
||||||
|
|||||||
@ -99,7 +99,7 @@ def command_permissions_check(bot, trigger, privslist):
|
|||||||
def bot_logging(bot, logtype, logentry, stdio=False):
|
def bot_logging(bot, logtype, logentry, stdio=False):
|
||||||
|
|
||||||
if 'SpiceBot_Logs' not in bot.memory:
|
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 + ""
|
logmessage = "[" + logtype + "] " + logentry + ""
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user