1 # Eloipool - Python Bitcoin pool server
2 # Copyright (C) 2011-2012 Luke Dashjr <luke-jr+eloipool@utopios.org>
3 # Copyright (C) 2012 Peter Leurs <kinlo@triplemining.com>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from collections import deque
21 from datetime import date
22 from time import sleep, time
28 _logger = logging.getLogger('logshares_files')
30 class logfile(threading.Thread):
31 def __init__(self, filename, *a, **k):
32 super().__init__(*a, **k)
37 def queueshare(self, line):
38 self.queue.append(line)
41 if len(self.queue) > 0:
42 with open(self.fn, "a") as logfile:
43 while len(self.queue)>0:
44 logfile.write(self.queue.popleft())
52 _logger.critical(traceback.format_exc())
54 def logShare(self, share):
56 address = share.get('remoteHost','?')
57 username = share['username']
58 ourresult = YN(not share.get('rejectReason', None))
59 upstreamresult = YN(share.get('upstreamResult', None)) or '-'
60 reason = share.get('rejectReason','-')
61 solution = share['solution']
63 logline = "{} {} {} {} {} {} {}\n".format(timestamp, address, username, ourresult, upstreamresult, reason, solution)
64 self.queueshare(logline)