Return log file of first file handler associated with the (root) logger.
        None if no such handler is found.
171994
def get_logfile(logger=None):
    
    logger = logger or logging.getLogger()
    handlers = [i for i in logger.handlers if isinstance(i, logging.FileHandler)]
    return handlers[0].baseFilename if handlers else None
75872
def remove_all_handlers(logger=None):
    
    if not isinstance(logger, logging.Logger):
        logger = logging.getLogger(logger)

    remove_file_handlers(logger)
    logger.handlers = []
1211542
def log_file(self):
        
        log_file = self.get('log')
        if not log_file:
            log_file = '%s.log' % (self.name)
            self.set('log', log_file)
        return os.path.join(self.initial_dir, self.get('log'))
628083
def capture_logger(name):
    
    import logging

    logger = logging.getLogger(name)
    try:
        import StringIO
        stream = StringIO.StringIO()
    except ImportError:
        from io import StringIO
        stream = StringIO()
    handler = logging.StreamHandler(stream)
    logger.addHandler(handler)
    try:
        yield stream
    finally:
        logger.removeHandler(handler)
795054
def get_logger(self, logfilename=None):
        
        if self._logger is None:
            self._logger = logging.getLogger('invenio_upgrader')
            self._logger.setLevel(logging.INFO)

            if logfilename:
                fh = logging.FileHandler(logfilename)
                fh.setLevel(logging.INFO)
                fh.setFormatter(self._logger_file_fmtter)
                self._logger.addHandler(fh)

            ch = logging.StreamHandler(sys.stdout)
            ch.setLevel(logging.INFO)
            ch.setFormatter(self._logger_console_fmtter)

            self._logger.addHandler(ch)

            # Replace show warnings (documented in Python manual)
            def showwarning(message, dummy_category, dummy_filename,
                            dummy_lineno, *dummy_args):
                self.warning_occured += 1
                logger = self.get_logger()
                logger.warning(message)
            warnings.showwarning = showwarning

            self._teardown_log_prefix()

        return self._logger
1232507
def logger(self):
        
        if self._logger is None:
            self._logger = self.new_logger()
        return self._logger
1297768
def getLogger(name):
    '''  '''

    # Create logger and add a default NULL handler
    log = logging.getLogger(name)
    log.addHandler(_NullHandler())

    return log
111454
def get_logger(name, CFG=None):
    

    logger = logging.getLogger(name)

    if CFG:
        # Make log directory if it doesn't exist
        for handler in CFG.get('handlers', {}).itervalues():
            if 'filename' in handler:
                log_dir = os.path.dirname(handler['filename'])
                if not os.path.exists(log_dir):
                    os.makedirs(log_dir)
        try:
            #TODO: This requires python 2.7
            logging.config.dictConfig(CFG)
        except AttributeError:
            print >> sys.stderr, '"logging.config.dictConfig" doesn\'t seem to be supported in your python'
            raise

    return logger
347474
def getLogger(cls):
        
        # Only do the setup once, so we don't add a handler every time we log. Use a lock to do
        # so safely even if we're being called in different threads. Use double-checked locking
        # to reduce the overhead introduced by the lock.
        if cls.logger is None:
            with cls.lock:
                if cls.logger is None:
                    cls.logger = logging.getLogger('toil-rt')
                    try:
                        level = os.environ[cls.envPrefix + 'LEVEL']
                    except KeyError:
                        # There is no server running on the leader, so suppress most log messages
                        # and skip the UDP stuff.
                        cls.logger.setLevel(logging.CRITICAL)
                    else:
                        # Adopt the logging level set on the leader.
                        toil.lib.bioio.setLogLevel(level, cls.logger)
                        try:
                            address = os.environ[cls.envPrefix + 'ADDRESS']
                        except KeyError:
                            pass
                        else:
                            # We know where to send messages to, so send them.
                            host, port = address.split(':')
                            cls.logger.addHandler(JSONDatagramHandler(host, int(port)))
        return cls.logger
1318826
def get_log_file(self, api=None):
        
        api = api or self._API
        log_file_data = self.execution_details.get('log_file')
        return File(api=api, **log_file_data) if log_file_data else None
376058
def getLogger(name=None):
    

    if name:
        logger = SLogger.manager.getLogger(name)
        return logger
    else:
        return rootLogger
237700
def getLogger(name=None):

    '''
    
    '''

    logger = logging.getLogger(name=name)

    if not hasattr(logger, 'd'):
        def d(self, msg, *args, **kwargs):
            return self.log(DEBUG, msg, *args, **kwargs)
        logger.d = types.MethodType(d, logger)

    if not hasattr(logger, 'v'):
        def v(self, msg, *args, **kwargs):
            return self.log(VERBOSE, msg, *args, **kwargs)
        logger.v = types.MethodType(v, logger)

    if not hasattr(logger, 'i'):
        def i(self, msg, *args, **kwargs):
            return self.log(INFO, msg, *args, **kwargs)
        logger.i = types.MethodType(i, logger)

    if not hasattr(logger, 'w'):
        def w(self, msg, *args, **kwargs):
            return self.log(WARN, msg, *args, **kwargs)
        logger.w = types.MethodType(w, logger)

    if not hasattr(logger, 'e'):
        def e(self, msg, *args, **kwargs):
            return self.log(ERROR, msg, *args, **kwargs)
        logger.e = types.MethodType(e, logger)

    return logger
859557
def get_log_filehandle(context):
    
    log_file_name = get_log_filename(context)
    makedirs(context.config['task_log_dir'])
    with open(log_file_name, "w", encoding="utf-8") as filehandle:
        yield filehandle
1090099
def start_file_logger(self, name, log_file_level=logging.DEBUG, log_file_path='./'):
        """"""

        log_file_path = os.path.expanduser(log_file_path) / '{}.log'.format(name)
        logdir = log_file_path.parent

        try:
            logdir.mkdir(parents=True, exist_ok=True)

            # If the log file exists, backs it up before creating a new file handler
            if log_file_path.exists():
                strtime = datetime.datetime.utcnow().strftime('%Y-%m-%d_%H:%M:%S')
                shutil.move(log_file_path, log_file_path + '.' + strtime)

            self.fh = TimedRotatingFileHandler(str(log_file_path), when='midnight', utc=True)
            self.fh.suffix = '%Y-%m-%d_%H:%M:%S'
        except (IOError, OSError) as ee:
            warnings.warn('log file {0!r} could not be opened for writing: '
                          '{1}'.format(log_file_path, ee), RuntimeWarning)
        else:
            self.fh.setFormatter(fmt)
            self.addHandler(self.fh)
            self.fh.setLevel(log_file_level)

        self.log_filename = log_file_path
173951
def _get_logger_file_handles(self):
        
        handles = []
        for handler in self.logger.handlers:
            # The following code works for logging's SysLogHandler,
            # StreamHandler, SocketHandler, and their subclasses.
            for attr in ['sock', 'socket', 'stream']:
                try:
                    handle = getattr(handler, attr)
                    if handle:
                        handles.append(handle)
                    break
                except AttributeError:
                    continue
        return handles
359299
def get_logger(verbosity):
    
    logger = logging.getLogger(__name__)
    logger.setLevel({
        0: DEFAULT_LOGGING_LEVEL,
        1: logging.INFO,
        2: logging.DEBUG
    }.get(min(2, verbosity), DEFAULT_LOGGING_LEVEL))
    logger.handlers = []
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(logging.Formatter('%(name)s - %(levelname)s - %(message)s'))
    logger.addHandler(handler)
    return logger
1141479
def get_logger(name, file_name=None, stream=None, template=None, propagate=False, level=None):
    

    logger = logging.getLogger(name)
    running_tests = (
        'test' in sys.argv  # running with setup.py
        or sys.argv[0].endswith('py.test'))  # running with py.test
    if running_tests and not level:
        # testing without level, this means tester does not want to see any log messages.
        level = logging.CRITICAL

    if not level:
        level = logging.INFO
    logger.setLevel(level)
    logger.propagate = propagate

    formatter = logging.Formatter(template)

    if not stream:
        stream = sys.stdout

    logger.handlers = []
    handler = logging.StreamHandler(stream=stream)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    if file_name:
        handler = logging.FileHandler(file_name)
        handler.setFormatter(logging.Formatter('%(asctime)s '+template))
        logger.addHandler(handler)

    return logger