Add a file handler to the global logger.
4903
def add_filehandler(level, fmt, filename, mode, backup_count, limit, when):
    """"""
    kwargs = {}
 
    # If the filename is not set, use the default filename
    if filename is None:
        filename = getattr(sys.modules['__main__'], '__file__', 'log.py')
        filename = os.path.basename(filename.replace('.py', '.log'))
        filename = os.path.join('/tmp', filename)

    if not os.path.exists(os.path.dirname(filename)):
        os.mkdir(os.path.dirname(filename))

    kwargs['filename'] = filename
 
    # Choose the filehandler based on the passed arguments
    if backup_count == 0:  # Use FileHandler
        cls = logging.FileHandler
        kwargs['mode'] = mode
    elif when is None:  # Use RotatingFileHandler
        cls = logging.handlers.RotatingFileHandler
        kwargs['maxBytes'] = limit
        kwargs['backupCount'] = backup_count
        kwargs['mode'] = mode
    else:  # Use TimedRotatingFileHandler
        cls = logging.handlers.TimedRotatingFileHandler
        kwargs['when'] = when
        kwargs['interval'] = limit
        kwargs['backupCount'] = backup_count
 
    return add_handler(cls, level, fmt, False, **kwargs)
528227
def initLogger():
    '''
    
    '''
    global logger
    logger = logging.getLogger('root')
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.INFO)
    formatter = logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s", "%Y-%m-%d %H:%M:%S")
    ch.setFormatter(formatter)
    logger.addHandler(ch)
308694
def SetLogger(logger):
  """"""
  global log_info_message
  global log_warning_message
  global log_error_message
  log_info_message = logger.info
  log_warning_message = logger.warning
  log_error_message = logger.error
  logger.addFilter(LineNoFilter())
333511
def make_default_logger(name=INTERNAL_LOGGER_NAME, level=logging.INFO,
                        fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s'):
    """"""
    logger = logging.getLogger(name)
    logger.setLevel(level)
    if not logger.handlers:
        handler = logging.StreamHandler(sys.stderr)
        handler.setLevel(level)
        formatter = logging.Formatter(fmt)
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    return logger
344433
protected void addMsgToLogHandler(String msgId, String handlerId) {
        Set<String> logHandlerIdSet = getOrCreateLogHandlerIdSet(msgId);
        logHandlerIdSet.add(handlerId);
    }
321441
def addHandler(name, basepath=None, baseurl=None, allowDownscale=False):
    """"""
    if basepath is None:
        basepath = '.'
    _handlers.append(_handler_classes[name](basepath, baseurl, allowDownscale))
431987
def add_log_file(path):
    
    logfile_handler = RotatingFileHandler(
        path, maxBytes=50000, backupCount=2)
    formatter = logging.Formatter(
        fmt='%(asctime)s %(levelname)s %(module)s - %(message)s',
        datefmt="%d-%b-%Y %H:%M:%S")
    logfile_handler.setFormatter(formatter)
    geoparse_logger.addHandler(logfile_handler)
733222
def addLogger(self, logger, level=logging.INFO):
        
        if isinstance(logger, logging.Logger):
            logger = logger.name
        
        if logger in self._loggers:
            return
        
        # allow the handler to determine the level for this logger
        if logger == 'root':
            _log = logging.getLogger()
        else:
            _log = logging.getLogger(logger)
        
        _log.addHandler(self.handler())
        
        self._loggers.add(logger)
        self.handler().setLoggerLevel(logger, level)
1165190
def configure_file_logger(name, log_dir, log_level=logging.DEBUG):
    """"""
    from .srothandler import SizeRotatingFileHandler

    root = logging.getLogger()
    root.setLevel(log_level)
    handler = SizeRotatingFileHandler(os.path.join(log_dir, '%s.log' % name))
    handler.setLevel(log_level)
    handler.setFormatter(logging.Formatter(LOG_FORMAT_STANDARD))

    root.addHandler(handler)
524733
def install_handler(self, app):
        """"""
        # Configure python logging
        if app.config['LOGGING_CONSOLE_PYWARNINGS']:
            self.capture_pywarnings(logging.StreamHandler())

        if app.config['LOGGING_CONSOLE_LEVEL'] is not None:
            for h in app.logger.handlers:
                h.setLevel(app.config['LOGGING_CONSOLE_LEVEL'])

        # Add request_id to log record
        app.logger.addFilter(add_request_id_filter)
750181
def use_file(self, enabled=True,
                 file_name=None,
                 level=logging.WARNING,
                 when='d',
                 interval=1,
                 backup_count=30,
                 delay=False,
                 utc=False,
                 at_time=None,
                 log_format=None,
                 date_format=None):
        
        if enabled:
            if not self.__file_handler:
                assert file_name, 'File name is missing!'

                # Create new TimedRotatingFileHandler instance
                kwargs = {
                    'filename': file_name,
                    'when': when,
                    'interval': interval,
                    'backupCount': backup_count,
                    'encoding': 'UTF-8',
                    'delay': delay,
                    'utc': utc,
                }

                if sys.version_info[0] >= 3:
                    kwargs['atTime'] = at_time

                self.__file_handler = TimedRotatingFileHandler(**kwargs)

                # Use this format for default case
                if not log_format:
                    log_format = '%(asctime)s %(name)s[%(process)d] ' \
                                 '%(programname)s/%(module)s/%(funcName)s[%(lineno)d] ' \
                                 '%(levelname)s %(message)s'

                # Set formatter
                formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
                self.__file_handler.setFormatter(fmt=formatter)

                # Set level for this handler
                self.__file_handler.setLevel(level=level)

                # Add this handler to logger
                self.add_handler(hdlr=self.__file_handler)
        elif self.__file_handler:
            # Remove handler from logger
            self.remove_handler(hdlr=self.__file_handler)
            self.__file_handler = None
1071112
def init_logger_file(log_file, log_level='INFO'):
    
    log_level = LOG_LEVELS[log_level] if log_level in LOG_LEVELS.keys() else logging.INFO

    ROOT_LOG.setLevel(log_level)

    file_handle = logging.FileHandler(log_file)
    file_handle.setLevel(log_level)
    file_handle.setFormatter(formatter)
    ROOT_LOG.addHandler(file_handle)
575558
def add_loghandler (handler):
    """"""
    format = "%(levelname)s %(name)s %(asctime)s %(threadName)s %(message)s"
    handler.setFormatter(logging.Formatter(format))
    logging.getLogger(LOG_ROOT).addHandler(handler)
    logging.getLogger().addHandler(handler)
1211839
def file_handler(name, logname, filename, mode='a', encoding=None,
                 delay=False):
    

    return wrap_log_handler(logging.FileHandler(
        filename, mode=mode, encoding=encoding, delay=delay))
568196
def _init_file_logger(logger, level, log_path, log_size, log_count):
    
    if level not in [logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]:
        level = logging.DEBUG

    for h in logger.handlers:
        if isinstance(h, logging.handlers.RotatingFileHandler):
            if h.level == level:
                return

    fh = logging.handlers.RotatingFileHandler(
        log_path, maxBytes=log_size, backupCount=log_count)
    fh.setLevel(level)
    fh.setFormatter(_formatter)
    logger.addHandler(fh)
235866
def add_file_task(self, dir_name=None):
        ''''''
        file_dialog = Gtk.FileChooserDialog(_('Choose Files..'),
                self.app.window, Gtk.FileChooserAction.OPEN,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        file_dialog.set_modal(True)
        file_dialog.set_select_multiple(True)
        file_dialog.set_default_response(Gtk.ResponseType.OK)
        response = file_dialog.run()
        if response != Gtk.ResponseType.OK:
            file_dialog.destroy()
            return
        source_paths = file_dialog.get_filenames()
        file_dialog.destroy()
        if source_paths:
            self.upload_files(source_paths, dir_name)
1169411
def _add_log_file(filename):
    """"""
    handler = logging.FileHandler(filename)

    handler.setLevel(logging.DEBUG)
    formatter = _Formatter(fmt=_logger_fmt,
                           datefmt='%Y-%m-%d %H:%M:%S')
    handler.setFormatter(formatter)
    logging.getLogger().addHandler(handler)