summaryrefslogtreecommitdiffstats
path: root/utils.py
blob: 9fa347626d0b4f0fc65d28ad4da6cd848197fc03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from logging import Handler


class SqlHandler(Handler):

    def __init__(self, session):
        Handler.__init__(self)
        self.session = session
        self.count = 0

    def emit(self, record):
        self.session.add(record.msg)
        self.count += 1
        if self.count >= 100:
            self.session.commit()
            self.count = 0

    def close(self):
        self.session.commit()