11import logging
22import threading
3- from collections import Callable
43from datetime import datetime
54
65from quickbase_client import QuickbaseTableClient
1312class QuickbaseLogHandler (logging .Handler ):
1413 """Class for sending logs to a specific Quickbase table.
1514
16- You supply it with a table client to the logs table, and the handler will send logs to that
17- table in a non-blocking background thread.
15+ You supply it with a table client to the logs table, and the handler will send logs
16+ to that table in a non-blocking background thread.
1817
19- This uses the higher-level QuickbaseTableClient APIs. So you will have to create a class for
20- your table you want to send logs to.
18+ This uses the higher-level QuickbaseTableClient APIs. So you will have to
19+ create a class for your table you want to send logs to.
2120 """
2221
2322 def __init__ (self , logs_table_client : QuickbaseTableClient ):
@@ -35,9 +34,17 @@ def __init__(self, logs_table_client: QuickbaseTableClient):
3534 super ().__init__ ()
3635
3736 @staticmethod
38- def with_record_factory (
39- logs_table_client : QuickbaseTableClient , record_factory : Callable
40- ):
37+ def with_record_factory (logs_table_client : QuickbaseTableClient , record_factory ):
38+ """Create a logger using a function to make records.
39+
40+ :param logs_table_client:
41+ The QuickbaseTableClient for the logs to go to.
42+
43+ :param record_factory:
44+ A function which takes a `logging.LogRecord` and creates the relevant
45+ record (instance of a :class:`~QuickbaseTable`).
46+ """
47+
4148 class _CustomRecordFactoryHandler (QuickbaseLogHandler ):
4249 def record_factory (self , record : logging .LogRecord ):
4350 return record_factory (record )
@@ -46,9 +53,9 @@ def record_factory(self, record: logging.LogRecord):
4653
4754 def record_factory (self , record : logging .LogRecord ):
4855 """
49- Create a :class:`~QuickbaseTable` record object given a LogRecord. By default, this
50- assumes the associated table, under the handlers table client, has properties `when`,
51- ` level`, and `message`.
56+ Create a :class:`~QuickbaseTable` record object given a LogRecord. By default,
57+ this assumes the associated table, under the handlers table client, has
58+ properties ``when``, `` level`` , and `` message` `.
5259
5360 :param record: The logging.LogRecord.
5461 :return: A QuickbaseTable record object.
@@ -60,7 +67,7 @@ def record_factory(self, record: logging.LogRecord):
6067 )
6168
6269 def emit (self , record ):
63- """Calls :meth:`~record_factory` and starts a separate thread to send it to Quickbase."""
70+ """Calls :meth:`~record_factory` and starts a thread to send it to Quickbase."""
6471 t = threading .Thread (target = self ._do_emit , args = [record ])
6572 t .start ()
6673
0 commit comments