Squid url redirector

Diff
anonymous

Diff

Differences From Artifact [568859367f]:

To Artifact [29eb01c1f2]:


104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119

120
121
122

123
124
125
126
127
128
129







-
+








-



-







	def __init__(self):
		logging.handlers.SysLogHandler.__init__(self, '/dev/log')
		self._tail = gevent.queue.Queue()
		self._worker = None

	def emit(self, record):
		# my syslog is broken and cannot into UTF-8 BOM
		record.msg = str(record.msg)
		record.msg = record.msg.encode('utf-8')
		self._tail.put(record)
		if self._worker == None:
			# in case queue is empty we will spawn new worker
			# all workers are logged so we can kill them on close()
			self._worker = gevent.spawn(self._writer)

	def _writer(self):
		# here we are locking the queue so we can be sure we are the only one
		print('syslog start')
		while not self._tail.empty():
			logging.handlers.SysLogHandler.emit(self, self._tail.get())
		self._worker = None
		print('syslog end')

	def close(self):
		if self._worker != None:
			gevent.kill(self._worker)
		logging.handlers.SysLogHandler.close(self)

logger = logging.getLogger('squidTag')