Skip to content

Instantly share code, notes, and snippets.

@jeqo
Last active September 25, 2022 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeqo/1960d1895a48cc1103206524cfc5031b to your computer and use it in GitHub Desktop.
Save jeqo/1960d1895a48cc1103206524cfc5031b to your computer and use it in GitHub Desktop.
sqlite-utils to load log4j log files into sqlite
# regex demo: https://regex101.com/r/2AxwfE/1
sqlite-utils insert /tmp/kafka-logs-test.db logs server.log.2022-09-24-21 --text --convert "
import re
r = re.compile(r'^\[(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3})\]\s(?P<level>\w+)\s(?P<log>(.+(\n(?\!\[).+|)+))', re.MULTILINE)
def convert(text):
rows = [m.groupdict() for m in r.finditer(text)]
for row in rows:
row.update({'server': 'localhost'})
row.update({'component': 'broker'})
return rows
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment