build_logger

    :param name: name that shows in the logger
    :param config: name of the config file
    :param log_level: level to log
    :param log_config_path: path to log config file
768500
def build_logger(
    name=os.getenv(
        "LOG_NAME",
        "client"),
    config="logging.json",
    log_level=logging.INFO,
    log_config_path="{}/logging.json".format(
        os.getenv(
            "LOG_CFG",
            os.path.dirname(os.path.realpath(__file__))))):
    
    use_config = ("./log/{}").format(
                    "{}".format(
                        config))
    if not os.path.exists(use_config):
        use_config = log_config_path
        if not os.path.exists(use_config):
            use_config = ("./antinex_client/log/{}").format(
                            "logging.json")
    # find the log processing

    setup_logging(
        default_level=log_level,
        default_path=use_config)

    return logging.getLogger(name)
1161362
def configure_logger(logger, filename, folder, log_level):
    '''
    '''
    fmt = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
    if folder is not None:
        log_file = os.path.join(folder, filename)
        hdl = logging.FileHandler(log_file)
        hdl.setFormatter(fmt)
        hdl.setLevel(log_level)
        logger.addHandler(hdl)
    shdl = logging.StreamHandler()
    shdl.setLevel(log_level)
    shdl.setFormatter(fmt)
    logger.addHandler(shdl)
    logger.setLevel(log_level)
1326491
def set_logger_level(logger_name, log_level='error'):
    '''
    
    '''
    logging.getLogger(logger_name).setLevel(
        LOG_LEVELS.get(log_level.lower(), logging.ERROR)
    )
759034
def log_config(log_level: Union[str, int]) -> dict:
    
    if isinstance(log_level, int):
        # to match django
        log_level = {3: 'DEBUG', 2: 'INFO'}.get(log_level, 'WARNING')
    assert log_level in {'DEBUG', 'INFO', 'WARNING', 'ERROR'}, 'wrong log level %s' % log_level
    return {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'default': {'format': '%(message)s'},
            'indent': {'format': '    %(message)s'},
        },
        'handlers': {
            'default': {
                'level': log_level,
                'class': 'grablib.common.ClickHandler',
                'formatter': 'default'
            },
            'progress': {
                'level': log_level,
                'class': 'grablib.common.ProgressHandler',
                'formatter': 'indent'
            },
        },
        'loggers': {
            main_logger.name: {
                'handlers': ['default'],
                'level': log_level,
                'propagate': False,
            },
            progress_logger.name: {
                'handlers': ['progress'],
                'level': log_level,
                'propagate': False,
            },
        },
    }
1337533
def logging_level(level):
    
    level = level.upper()
    levels = [DEBUG, INFO, WARNING, ERROR, CRITICAL, VERBOSE]
    level_names = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'VERBOSE']

    if level not in level_names:
        raise Exception("Level %r not in %r" % (level, levels))

    param_logger = get_logger()
    logging_level = param_logger.getEffectiveLevel()
    param_logger.setLevel(levels[level_names.index(level)])
    try:
        yield None
    finally:
        param_logger.setLevel(logging_level)
1048147
def setup_log(name):
    '''
    '''
    _log = logging.getLogger(name)
    _log.setLevel(GLOBAL_LOG_LEVEL)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - [%(name)s] %(message)s')
    handler.setFormatter(formatter)
    _log.addHandler(handler)
    _log.addFilter(XBMCFilter('[%s] ' % name))
    return _log
250962
def setup_logging(loglevel):
    
    logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
    logging.basicConfig(level=loglevel, stream=sys.stdout,
                        format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
1297723
def _create_logger(name='fmf', level=None):
        
        # Create logger, handler and formatter
        logger = logging.getLogger(name)
        handler = logging.StreamHandler()
        handler.setFormatter(Logging.ColoredFormatter())
        logger.addHandler(handler)
        # Save log levels in the logger itself (backward compatibility)
        for level in Logging.LEVELS:
            setattr(logger, level, getattr(logging, level))
        # Additional logging constants and methods for cache and xmlrpc
        logger.DATA = LOG_DATA
        logger.CACHE = LOG_CACHE
        logger.ALL = LOG_ALL
        logger.cache = lambda message: logger.log(LOG_CACHE, message) # NOQA
        logger.data = lambda message: logger.log(LOG_DATA, message) # NOQA
        logger.all = lambda message: logger.log(LOG_ALL, message) # NOQA
        return logger
1329962
public void configLogger()
    {
        Map<String, Level> logLevels = new HashMap<String, Level>();
        logLevels.put("trace", Level.TRACE);
        logLevels.put("debug", Level.DEBUG);
        logLevels.put("info", Level.INFO);
        logLevels.put("warning", Level.WARNING);
        logLevels.put("error", Level.ERROR);

        if( this.get("logging_log_type", "file").equals("file") ){

            DateFormat dateFormat = new SimpleDateFormat(this.get("logging_current_date_format","yyyy-MM-dd"));
            Date date = new Date();
            String logFileName = (this.get("logging_file_format", "current_date").equals("current_date")) ? dateFormat.format(date) + ".log" : this.get("logging_file_format", "current_date") + ".log";
            Configurator.defaultConfig()
                .writer(new FileWriter(this.get("logging_file_path", "src/main/java/resources/") + logFileName, (this.get("logging_buffered", "false").equals("true")) ? true : false, (this.get("logging_append", "true").equals("true")) ? true : false))
                .level((logLevels.containsKey(this.get("logging_level","debug"))) ? logLevels.get(this.get("logging_level","debug")) : Level.INFO)
                .activate();

        }else if( this.get("logging_log_type", "file").equals("both") ){

            DateFormat dateFormat = new SimpleDateFormat(this.get("logging_current_date_format","yyyy-MM-dd"));
            Date date = new Date();
            String logFileName = (this.get("logging_file_format", "current_date").equals("current_date")) ? dateFormat.format(date) + ".log" : this.get("logging_file_format", "current_date") + ".log";
            Configurator.defaultConfig()
                .writer(new ConsoleWriter())
                .addWriter(new FileWriter(this.get("logging_file_path", "src/main/java/resources/") + logFileName))
                .level((logLevels.containsKey(this.get("logging_level","debug"))) ? logLevels.get(this.get("logging_level","debug")) : Level.INFO)
                .activate();

        }else{

            Configurator.defaultConfig()
                .writer(new ConsoleWriter())
                .level((logLevels.containsKey(this.get("logging_level","debug"))) ? logLevels.get(this.get("logging_level","debug")) : Level.INFO)
                .activate();

        }
    }
325361
def setup_logging(
    config='logging.yaml',
    default_level=logging.INFO,
    env_key='LOG_CFG'
):
    
    path = config
    value = os.getenv(env_key, None)
    if value:
        path = value

    if path.exists():
        with open(path, 'rt') as f:
            config = yaml.safe_load(f.read())
        logging.config.dictConfig(config)
    else:
        print('cannot read: ' + str(path))
        logging.basicConfig(level=default_level)
489718
def getLogger(name):
    """"""
    logger = logging.getLogger(name)
    # note: the level might be adjusted via '-v' option
    logger.setLevel(logging_config['loggers']['gcdt']['level'])
    return logger
176919
def getLogger(name, level = logging.INFO):
        
        # create logger
        logger = logging.getLogger(name) 
        logger.setLevel(level)
        # create console handler and set level to debug
        ch = logging.StreamHandler()
        ch.setLevel(level)
        # create formatter
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        # add formatter to ch
        ch.setFormatter(formatter)
        # add ch to logger
        logger.addHandler(ch)
        return logger
107351
def setup_logger(log_file, level=logging.DEBUG):
    ''''''
    cfg = AppBuilder.get_pcfg()
    logger = cfg['log_module']
    # todo make sure structlog is compliant and that logbook is also the correct name???
    assert logger in ("logging", "logbook", "structlog"), 'bad logger specified'
    exec("import {0};logging = {0}".format(logger))

    AppBuilder.logger = logging

    logging.basicConfig(
        filename=log_file,
        filemode='w',
        level=level,
        format='%(asctime)s:%(levelname)s: %(message)s')  # one run
    logging.debug('System is: %s' % platform.platform())
    logging.debug('Python archetecture is: %s' % platform.architecture()[0])
    logging.debug('Machine archetecture is: %s' % platform.machine())

    set_windows_permissions(log_file)
836214
def logToFile(path, level=logging.INFO):
    
    logger = logging.getLogger()
    logger.setLevel(level)
    formatter = logging.Formatter(
        '%(asctime)s %(name)s %(levelname)s %(message)s')
    handler = logging.FileHandler(path)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
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']
                )
            )
579809
def log_init(level):
    
    log = logging.getLogger()
    hdlr = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    log.addHandler(hdlr)
    log.setLevel(level)
791231
def configure(name, logfile, loglevel=logging.DEBUG):
        

        #        logging.config.dictConfig({
        #                'version': 1,
        #                'disable_existing_loggers': False})

        logger = logging.getLogger(name)

        # Don't propagate to root logger
        logger.propagate = False
        logger.setLevel(logging.DEBUG)

        datefmt = '%Y-%m-%d %H:%M:%S'
        format_stream = ('%(asctime)s %(levelname)-8s'
                         '%(name)s.%(funcName)s(): %(message)s')
        format_file = ('%(asctime)s %(levelname)-8s'
                       '%(name)s.%(funcName)s(): %(message)s')
#        format_file = ('%(asctime)s %(levelname)-8s '
#                       '%(name)s.%(funcName)s() '
#                       '[%(filename)s:%(lineno)d]: %(message)s')

        if not logger.handlers:

            # Add a file handler
            if logfile is not None:
                logfile = logfile.replace('.log', '') + '.log'
                fh = logging.FileHandler(logfile)
                fh.setLevel(logging.DEBUG)
                fh.setFormatter(logging.Formatter(format_file, datefmt))
                logger.addHandler(fh)

            # Add a stream handler
            ch = logging.StreamHandler()
            ch.setLevel(loglevel)
            ch.setFormatter(logging.Formatter(format_stream, datefmt))
            logger.addHandler(ch)
        else:
            logger.handlers[-1].setLevel(loglevel)

        return logger