diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-06 17:56:02 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-06 17:56:02 -0400 |
| commit | d1a77fac18e25df1093172f15fb8925c4545a7b5 (patch) | |
| tree | a5914472db4073d79444e86c05cdf56cfaeb1a31 /utils.py | |
| download | tracker-d1a77fac18e25df1093172f15fb8925c4545a7b5.tar.gz | |
Initial commit, X events tracking
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..9fa3476 --- /dev/null +++ b/utils.py @@ -0,0 +1,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() |
