Mercurial > touhou
comparison pytouhou/utils/helpers.py @ 58:3da4de9decd0
Use logging module
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 23 Aug 2011 21:01:50 +0200 |
parents | ab826bc29aa2 |
children | 04ae31809dc7 |
comparison
equal
deleted
inserted
replaced
57:694f25881d0f | 58:3da4de9decd0 |
---|---|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 ## GNU General Public License for more details. | 12 ## GNU General Public License for more details. |
13 ## | 13 ## |
14 | 14 |
15 | |
16 from logging import StreamHandler, Formatter, getLogger | |
17 | |
18 | |
19 def get_logger(name): | |
20 handler = StreamHandler() | |
21 formatter = Formatter(fmt='[%(name)s] [%(levelname)s]: %(message)s') | |
22 handler.setFormatter(formatter) | |
23 logger = getLogger(name) | |
24 logger.addHandler(handler) | |
25 logger.propagate = False | |
26 return logger | |
27 | |
28 | |
15 def read_string(file, size, encoding=None): | 29 def read_string(file, size, encoding=None): |
16 data = file.read(size) | 30 data = file.read(size) |
17 | 31 |
18 try: | 32 try: |
19 data = data[:data.index(b'\x00')] | 33 data = data[:data.index(b'\x00')] |
22 | 36 |
23 if encoding: | 37 if encoding: |
24 return data.decode(encoding) | 38 return data.decode(encoding) |
25 else: | 39 else: |
26 return data | 40 return data |
41 |