Attach file handler to RASH logger.

    :type cfstore: rash.config.ConfigStore
480933
def setup_daemon_log_file(cfstore):
    
    level = loglevel(cfstore.daemon_log_level)
    handler = logging.FileHandler(filename=cfstore.daemon_log_path)
    handler.setLevel(level)
    logger.setLevel(level)
    logger.addHandler(handler)
1332035
def setup_main_logger(file_logging=True, console=True, path: Optional[str] = None, level=logging.INFO):
    
    if file_logging and console:
        log_config = LOGGING_CONFIGS["file_console"]  # type: ignore
    elif file_logging:
        log_config = LOGGING_CONFIGS["file_only"]
    elif console:
        log_config = LOGGING_CONFIGS["console_only"]
    else:
        log_config = LOGGING_CONFIGS["none"]

    if path:
        log_config["handlers"]["rotating"]["filename"] = path  # type: ignore

    for _, handler_config in log_config['handlers'].items():  # type: ignore
        handler_config['level'] = level

    logging.config.dictConfig(log_config)  # type: ignore

    def exception_hook(exc_type, exc_value, exc_traceback):
        if is_python34():
            # Python3.4 does not seem to handle logger.exception() well
            import traceback
            traceback = "".join(traceback.format_tb(exc_traceback)) + exc_type.name
            logging.error("Uncaught exception\n%s", traceback)
        else:
            logging.exception("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))

    sys.excepthook = exception_hook
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
817768
def _configure_root_logger(self):
        """"""
        root_logger = logging.getLogger()
        root_logger.setLevel(logging.DEBUG)
        if self.args.verbose:
            handler = logging.StreamHandler(sys.stdout)
        else:
            handler = logging.handlers.RotatingFileHandler(
                common.LOG_FILE,
                maxBytes=common.MAX_LOG_SIZE,
                backupCount=common.MAX_LOG_COUNT
            )
            handler.setLevel(logging.INFO)
        handler.setFormatter(logging.Formatter(common.LOG_FORMAT))
        root_logger.addHandler(handler)
229015
function (config) {
    config = config || {};
    Appender.call(this, config);

    /**
     * Log file name, initialized from the configuration. Folders up to the
     * file must exist beforehand.
     */
    this.fileName = config.fileName;

    /**
     * Append log events to the end of the file when true, clear the file
     * before writing the first log event otherwise.
     */
    this.appendToFile = (typeof config.append !== 'undefined') ?
      !!config.append :
      true;

    /**
     * True to log strings instead of objects
     */
    this.appendStrings = (typeof config.appendStrings !== 'undefined') ?
      config.appendStrings :
      true;

    /**
     * The file stream, initialized by the "start" function
     */
    this.stream = null;
  }
188543
def addFileHandler(self,filename='', dr='',lvl=1):
        
        fname = self.name
        if filename != '':
            fname = filename
        if '.' not in fname:
            fname+='.log'
        fh = logging.FileHandler(os.path.join(dr,fname))
        fh.setLevel(lvl)
        frmtString = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
        fFrmt = logging.Formatter(frmtString)
        fh.setFormatter(fFrmt)
        self.addHandler(fh)
567752
def logfile(targetfile="ros.log"):
    
    log = logging.getLogger(__name__)
    log.basicConfig(filename=str(targetfile))
1202590
def cli(config_path, verbose):
    """"""
    global config, store
    if not config_path:
        config_path = '/etc/record_recommender.yml'
    config = get_config(config_path)
    setup_logging(config)
    store = FileStore(config)
457423
def _attach_config(mfg_event, record):
  """"""
  if 'config' not in record.metadata:
    return
  attachment = mfg_event.attachment.add()
  attachment.name = 'config'
  attachment.value_binary = _convert_object_to_json(record.metadata['config'])
  attachment.type = test_runs_pb2.TEXT_UTF8
944211
def Logger(name, **kargs):
    
    path_dirs = PathDirs(**kargs)
    logging.captureWarnings(True)
    logger = logging.getLogger(name)
    logger.setLevel(logging.INFO)
    handler = logging.handlers.WatchedFileHandler(os.path.join(
        path_dirs.meta_dir, 'vent.log'))
    handler.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s:%(lineno)-4d - '
                                  '%(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    if not len(logger.handlers):
        logger.addHandler(handler)

    return logger
650024
def configure_logger(self):
        

        logger_name = 'brome_runner'

        self.logger = logging.getLogger(logger_name)

        format_ = BROME_CONFIG['logger_runner']['format']

        # Stream logger
        if BROME_CONFIG['logger_runner']['streamlogger']:
            sh = logging.StreamHandler()
            stream_formatter = logging.Formatter(format_)
            sh.setFormatter(stream_formatter)
            self.logger.addHandler(sh)

        # File logger
        if BROME_CONFIG['logger_runner']['filelogger'] and \
                self.runner_dir:

            self.log_file_path = os.path.join(
                    self.runner_dir,
                    '%s.log' % logger_name
            )
            self.relative_log_file_path = os.path.join(
                    self.relative_runner_dir,
                    '%s.log' % logger_name
            )

            fh = logging.FileHandler(
                self.log_file_path
            )
            file_formatter = logging.Formatter(format_)
            fh.setFormatter(file_formatter)
            self.logger.addHandler(fh)

        self.logger.setLevel(
            getattr(
                logging,
                BROME_CONFIG['logger_runner']['level']
                )
            )
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)
674005
def attach_event_handler(canvas, handler=close_on_esc_or_middlemouse):
    
    if getattr(canvas, "_py_event_dispatcher_attached", None):
        return

    event_dispatcher = C.TPyDispatcherProcessedEvent(handler)
    canvas.Connect("ProcessedEvent(int,int,int,TObject*)",
                   "TPyDispatcherProcessedEvent", event_dispatcher,
                   "Dispatch(int,int,int,TObject*)")

    # Attach a handler only once to each canvas, and keep the dispatcher alive
    canvas._py_event_dispatcher_attached = event_dispatcher
982001
def configureLogger(logFolder, logFile):
    '''  '''
    # Set debug level
    logLevel = 'DEBUG'
    logger = logging.getLogger()
    logger.setLevel(logLevel)

    # Format
    formatter = logging.Formatter('%(asctime)s - %(levelname)s | %(name)s -> %(message)s', '%Y-%m-%d %H:%M:%S')

    # Remove default handler to keep only clean one
    for hdlr in logger.handlers:
        logger.removeHandler(hdlr)

    # Create missing folder if needed
    if not os.path.exists(logFolder):
        os.makedirs(logFolder, 0700)

    #
    # ----------------------------
    #   CREATE CONSOLE HANDLER
    # ----------------------------
    #

    # Create console handler
    consoleh = logging.StreamHandler()
    consoleh.setLevel(logLevel)
    consoleh.setFormatter(formatter)

    # Set our custom handler
    logger.addHandler(consoleh)

    #
    # ----------------------------
    #   CREATE FILE HANDLER
    # ----------------------------
    #
    fileh = logging.FileHandler(logFile, 'a')
    fileh.setLevel(logLevel)
    fileh.setFormatter(formatter)

    # Set our custom handler
    logger.addHandler(fileh)
143441
def _setup_logger(self, level, log_file):
        """"""
        if logger.handlers:
            return
        level = getattr(logging, level.upper())
        logger.setLevel(level)
        formatter = logging.Formatter(
            '[%(levelname)s] %(asctime)s - %(module)s.%(funcName)s() - %(message)s')
        handler = logging.StreamHandler()
        logger.addHandler(handler)
        handler.setFormatter(formatter)
        if not log_file:
            return
        try:
            handler = TimedRotatingFileHandler(log_file)
        except IOError:
            logger.error("Could not write to %s, falling back to stdout",
                         log_file)
        else:
            logger.addHandler(handler)
            handler.setFormatter(formatter)
900307
def _registerHandler(self, handler):
        
        self._logger.addHandler(handler)
        self._handlers.append(handler)
101348
def logger_file(self, value):
        
        self.__logger_file = value
        if self.__logger_file:
            # If set logging file,
            # then add file handler and remove stream handler.
            self.logger_file_handler = logging.FileHandler(self.__logger_file)
            self.logger_file_handler.setFormatter(self.logger_formatter)
            for _, logger in six.iteritems(self.logger):
                logger.addHandler(self.logger_file_handler)
                if self.logger_stream_handler:
                    logger.removeHandler(self.logger_stream_handler)
        else:
            # If not set logging file,
            # then add stream handler and remove file handler.
            self.logger_stream_handler = logging.StreamHandler()
            self.logger_stream_handler.setFormatter(self.logger_formatter)
            for _, logger in six.iteritems(self.logger):
                logger.addHandler(self.logger_stream_handler)
                if self.logger_file_handler:
                    logger.removeHandler(self.logger_file_handler)