add message search function
This commit is contained in:
@@ -7,7 +7,7 @@ import shutil
|
|||||||
class LogHandlerSQLite(logging.Handler):
|
class LogHandlerSQLite(logging.Handler):
|
||||||
"""logging handler for sqlite3"""
|
"""logging handler for sqlite3"""
|
||||||
__AUTHOR__ = 'anima'
|
__AUTHOR__ = 'anima'
|
||||||
__VERSION__ = '1.0.0'
|
__VERSION__ = '1.1.0'
|
||||||
|
|
||||||
def __init__(self, level: int | str = 0, dbfile: str = 'logs.db') -> None:
|
def __init__(self, level: int | str = 0, dbfile: str = 'logs.db') -> None:
|
||||||
"""logging handler for sqlite3
|
"""logging handler for sqlite3
|
||||||
@@ -119,6 +119,17 @@ class LogHandlerSQLite(logging.Handler):
|
|||||||
return self.__db_query('selectLogsByPID', [pid])
|
return self.__db_query('selectLogsByPID', [pid])
|
||||||
else: return None
|
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
|
##> logging methods
|
||||||
def emit(self, record: logging.LogRecord) -> None:
|
def emit(self, record: logging.LogRecord) -> None:
|
||||||
"""save log to db
|
"""save log to db
|
||||||
@@ -148,5 +159,3 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
log.error('Here is a info')
|
log.error('Here is a info')
|
||||||
print(logDB.get_log_by_pid())
|
print(logDB.get_log_by_pid())
|
||||||
|
|
||||||
t = LogHandlerSQLite()
|
|
||||||
4
sql/selectLogsLikeMessage.sql
Normal file
4
sql/selectLogsLikeMessage.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
SELECT *
|
||||||
|
FROM logs
|
||||||
|
WHERE message like :1
|
||||||
|
;
|
||||||
Reference in New Issue
Block a user