Python logging.__dict__() Examples
The following are 4 code examples for showing how to use logging.__dict__(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
logging
, or try the search function
.
Example 1
Project: rhinobot_heroku Author: helionmusic File: __init__.py License: MIT License | 6 votes |
def _add_logger_level(levelname, level, *, func_name = None): """ :type levelname: str The reference name of the level, e.g. DEBUG, WARNING, etc :type level: int Numeric logging level :type func_name: str The name of the logger function to log to a level, e.g. "info" for log.info(...) """ func_name = func_name or levelname.lower() setattr(logging, levelname, level) logging.addLevelName(level, levelname) exec(_func_prototype.format(logger_func_name=func_name, levelname=levelname), logging.__dict__, locals()) setattr(logging.Logger, func_name, eval(func_name))
Example 2
Project: phoebe2 Author: phoebe-project File: __init__.py License: GNU General Public License v3.0 | 6 votes |
def add_filehandler(logger,style="default",flevel='DEBUG', filename=None,filemode='w'): name = "" #-- define formats if style=='default': format = '%(asctime)s %(name)-12s %(levelname)-7s %(message)s' datefmt = '%a, %d %b %Y %H:%M' elif style=='grandpa': format = '# %(levelname)-7s %(message)s' datefmt = '%a, %d %b %Y %H:%M' elif style=='minimal': format = '' datefmt = '%a, %d %b %Y %H:%M' flevel = logging.__dict__[flevel.upper()] logging.basicConfig(level=flevel, format=format,datefmt=datefmt, filename=filename,filemode=filemode) fh = logging.FileHandler(filename) fh.setLevel(flevel) formatter = logging.Formatter(fmt=format,datefmt=datefmt) fh.setFormatter(formatter) logging.getLogger(name).addHandler(fh) logging.getLogger(name).handlers[-1].level = flevel return logging.getLogger(name)
Example 3
Project: MusicBot Author: Just-Some-Bots File: __init__.py License: MIT License | 6 votes |
def _add_logger_level(levelname, level, *, func_name = None): """ :type levelname: str The reference name of the level, e.g. DEBUG, WARNING, etc :type level: int Numeric logging level :type func_name: str The name of the logger function to log to a level, e.g. "info" for log.info(...) """ func_name = func_name or levelname.lower() setattr(logging, levelname, level) logging.addLevelName(level, levelname) exec(_func_prototype.format(logger_func_name=func_name, levelname=levelname), logging.__dict__, locals()) setattr(logging.Logger, func_name, eval(func_name))
Example 4
Project: rfc5424-logging-handler Author: jobec File: conftest.py License: BSD 3-Clause "New" or "Revised" License | 4 votes |
def logger(): getpid_patch = patch('logging.os.getpid', return_value=111) getpid_patch.start() time_patch = patch('logging.time.time', return_value=946725071.111111) time_patch.start() localzone_patch = patch('rfc5424logging.handler.get_localzone', return_value=timezone) localzone_patch.start() hostname_patch = patch('rfc5424logging.handler.socket.gethostname', return_value="testhostname") hostname_patch.start() connect_patch = patch('logging.handlers.socket.socket.connect', side_effect=connect_mock) connect_patch.start() sendall_patch = patch('logging.handlers.socket.socket.sendall', side_effect=connect_mock) sendall_patch.start() if '_levelNames' in logging.__dict__: # Python 2.7 level_patch = patch.dict(logging._levelNames) level_patch.start() else: # Python 3.x level_patch1 = patch.dict(logging._levelToName) level_patch1.start() level_patch2 = patch.dict(logging._nameToLevel) level_patch2.start() logging.raiseExceptions = True logger = logging.getLogger() logger.setLevel(logging.DEBUG) yield logger getpid_patch.stop() time_patch.stop() localzone_patch.stop() hostname_patch.stop() connect_patch.stop() sendall_patch.stop() if '_levelNames' in logging.__dict__: # Python 2.7 level_patch.stop() else: # Python 3.x level_patch1.stop() level_patch2.stop() Rfc5424SysLogAdapter._extra_levels_enabled = False