1""" 2websocket - WebSocket client library for Python 3 4Copyright (C) 2010 Hiroki Ohtani(liris) 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1335 USA 20 21""" 22import logging 23 24_logger = logging.getLogger('websocket') 25_traceEnabled = False 26 27__all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace", 28 "isEnabledForError", "isEnabledForDebug"] 29 30 31def enableTrace(traceable): 32 """ 33 turn on/off the traceability. 34 35 traceable: boolean value. if set True, traceability is enabled. 36 """ 37 global _traceEnabled 38 _traceEnabled = traceable 39 if traceable: 40 if not _logger.handlers: 41 _logger.addHandler(logging.StreamHandler()) 42 _logger.setLevel(logging.DEBUG) 43 44 45def dump(title, message): 46 if _traceEnabled: 47 _logger.debug("--- " + title + " ---") 48 _logger.debug(message) 49 _logger.debug("-----------------------") 50 51 52def error(msg): 53 _logger.error(msg) 54 55 56def warning(msg): 57 _logger.warning(msg) 58 59 60def debug(msg): 61 _logger.debug(msg) 62 63 64def trace(msg): 65 if _traceEnabled: 66 _logger.debug(msg) 67 68 69def isEnabledForError(): 70 return _logger.isEnabledFor(logging.ERROR) 71 72 73def isEnabledForDebug(): 74 return _logger.isEnabledFor(logging.DEBUG) 75