Skip to content

Commit 1c01d29

Browse files
committed
Backport NullHandler for python2.6 support.
1 parent d5c05a4 commit 1c01d29

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

sc2reader/log_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# -*- coding: utf-8 -*-
22
import logging
33

4+
try:
5+
from logging import NullHandler
6+
except ImportError:
7+
# Copied from the Python 2.7 source code.
8+
class NullHandler(logging.Handler):
9+
"""
10+
This handler does nothing. It's intended to be used to avoid the
11+
"No handlers could be found for logger XXX" one-off warning. This is
12+
important for library code, which may contain code to log events. If a user
13+
of the library does not configure logging, the one-off warning might be
14+
produced; to avoid this, the library developer simply needs to instantiate
15+
a NullHandler and add it to the top-level logger of the library module or
16+
package.
17+
"""
18+
def handle(self, record):
19+
pass
20+
21+
def emit(self, record):
22+
pass
23+
24+
def createLock(self):
25+
self.lock = None
26+
427
LEVEL_MAP = dict(
528
DEBUG=logging.DEBUG,
629
INFO=logging.INFO,
@@ -10,7 +33,7 @@
1033
)
1134

1235
def setup():
13-
logging.getLogger('sc2reader').addHandler(logging.NullHandler())
36+
logging.getLogger('sc2reader').addHandler(NullHandler())
1437

1538
def log_to_file(filename, level='WARN', format=None, datefmt=None, **options):
1639
add_log_handler(logging.FileHandler(filename, **options),level, format, datefmt)

0 commit comments

Comments
 (0)