Browse Source

Add log line colours

master
JustAnotherArchivist 3 years ago
parent
commit
bc73fdb33f
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      irclog.py

+ 9
- 2
irclog.py View File

@@ -682,6 +682,13 @@ class Storage:

class WebServer:
logger = logging.getLogger('irclog.WebServer')
logStyleTag = '<style>' + " ".join([
'tr:target { background-color: yellow; }',
'tr.command_JOIN { color: green; }',
'tr.command_QUIT, tr.command_PART, tr.command_KICK, tr.command__CONNCLOSED { color: red; }',
'tr.command_NAMES { display: none; }',
'tr.command_NICK, tr.command_ACCOUNT, tr.command_MODE, tr.command_TOPIC, tr.command_TOPICWHO, tr.command_WHOX { color: grey; }'
]) + '</style>'

def __init__(self, config):
self.config = config
@@ -778,7 +785,7 @@ class WebServer:
fn = date.strftime('%Y-%m.log')
with open(os.path.join(self.config['storage']['path'], request.match_info["path"], fn), 'r') as fp:
lines = list(self._raw_to_lines(fp, filter = lambda ts, command, content: dateStart <= ts <= dateEnd))
return aiohttp.web.Response(text = f'<html><body><a href="/{request.match_info["path"]}/{(date - datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Previous day</a> <a href="/{request.match_info["path"]}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next day</a><br /><br />' + self._render_log(lines, request.match_info['path']) + '</body></html>', content_type = 'text/html')
return aiohttp.web.Response(text = f'<html><head>{self.logStyleTag}</head><body><a href="/{request.match_info["path"]}/{(date - datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Previous day</a> <a href="/{request.match_info["path"]}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next day</a><br /><br />' + self._render_log(lines, request.match_info['path']) + '</body></html>', content_type = 'text/html')

async def search(self, request):
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.path!r}')
@@ -789,7 +796,7 @@ class WebServer:
proc = await asyncio.create_subprocess_exec('grep', '--fixed-strings', '--recursive', '--no-filename', request.query['q'], os.path.join(self.config['storage']['path'], request.match_info['path'], ''), stdout = asyncio.subprocess.PIPE)
#TODO Limit size and runtime
stdout, _ = await proc.communicate()
return aiohttp.web.Response(text = '<html><body>' + self._render_log(self._raw_to_lines(stdout), request.match_info['path'], withDate = True) + '</body></html>', content_type = 'text/html')
return aiohttp.web.Response(text = '<html><head>{self.logStyleTag}</head><body>' + self._render_log(self._raw_to_lines(stdout), request.match_info['path'], withDate = True) + '</body></html>', content_type = 'text/html')


def configure_logging(config):


Loading…
Cancel
Save