Compare commits

..

1 Commits

Author SHA1 Message Date
1bbcb3d840 add message search function 2024-08-10 23:24:37 +02:00
2 changed files with 17 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ import shutil
class LogHandlerSQLite(logging.Handler):
"""logging handler for sqlite3"""
__AUTHOR__ = 'anima'
__VERSION__ = '1.0.0'
__VERSION__ = '1.1.0'
def __init__(self, level: int | str = 0, dbfile: str = 'logs.db') -> None:
"""logging handler for sqlite3
@@ -119,6 +119,17 @@ class LogHandlerSQLite(logging.Handler):
return self.__db_query('selectLogsByPID', [pid])
else: return None
def search_log(self, search: str) -> list[tuple] | None:
"""search str in log message
:param search: search string for message
:type search: str
:return: all matched log entrys or None
:rtype: list[tuple] | None
"""
return self.__db_query('selectLogsLikeMessage', [f'%{search}%'])
##> logging methods
def emit(self, record: logging.LogRecord) -> None:
"""save log to db
@@ -147,6 +158,4 @@ if __name__ == "__main__":
log.addHandler(logDB)
log.error('Here is a info')
print(logDB.get_log_by_pid())
t = LogHandlerSQLite()
print(logDB.get_log_by_pid())

View File

@@ -0,0 +1,4 @@
SELECT *
FROM logs
WHERE message like :1
;