Python logging.WARN Examples

The following are 30 code examples for showing how to use logging.WARN(). 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 want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module logging , or try the search function .

Example 1
Project: BASS   Author: Cisco-Talos   File: cmdline.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Bass")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Sample path") 

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO
        }[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG

    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 2
Project: BASS   Author: Cisco-Talos   File: whitelist.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Add samples to BASS whitelist")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
    parser.add_argument("sample", help = "Whitelist sample")

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO}[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG
    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 3
Project: BASS   Author: Cisco-Talos   File: client.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Find common ngrams in binary files")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("--output", type = str, default = None, help = "Output to file instead of stdout")
    parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
    parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Cluster samples")

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO}[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG
    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 4
Project: firefox_decrypt   Author: unode   File: firefox_decrypt.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setup_logging(args):
    """Setup the logging level and configure the basic logger
    """
    if args.verbose == 1:
        level = logging.INFO
    elif args.verbose >= 2:
        level = logging.DEBUG
    else:
        level = logging.WARN

    logging.basicConfig(
        format="%(asctime)s - %(levelname)s - %(message)s",
        level=level,
    )

    global LOG
    LOG = logging.getLogger(__name__) 
Example 5
Project: misp42splunk   Author: remg427   File: cim_actions.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def addjobinfo(self):
        """ The purpose of this method is to populate the job variable
        with the contents from REST (/services/search/jobs/<sid>)

        SPL-112815 - sendalert - not all $job.<param>$ parameters come through

        @raise Exception: raises Exception if search job information could not
                          be retrieved via REST (search/jobs) based on self.sid
        """
        self.job = {}
        if self.sid:
            try:
                response, content = rest.simpleRequest('search/jobs/%s' % self.sid,
                                        sessionKey=self.session_key,
                                        getargs={'output_mode': 'json'})
                if response.status == 200:
                    self.job = json.loads(content)['entry'][0]['content']
                    self.message('Successfully retrieved search job info')
                    self.logger.debug(self.job)
                else:
                    self.message('Could not retrieve search job info', level=logging.WARN)
            except Exception as e:
                self.message('Could not retrieve search job info', level=logging.WARN) 
Example 6
Project: ffw   Author: dobin   File: framework.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setupLoggingWithFile(config):
    # set up logging to file - see previous section for more details
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%m-%d %H:%M',
                        filename='ffw-debug.log',
                        filemode='w')
    # define a Handler which writes INFO messages or higher to the sys.stderr
    console = logging.StreamHandler()
    console.setLevel(logging.WARN)
    # set a format which is simpler for console use
    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
    # tell the handler to use this format
    console.setFormatter(formatter)
    # add the handler to the root logger
    logging.getLogger('').addHandler(console)

    # slaves will setup their own logging
    config["DebugWithFile"] = True 
Example 7
Project: ffw   Author: dobin   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setupSlaveLoggingWithFile(threadId):
    f = 'ffw-debug-slave-' + str(threadId) + '.log'

    fileh = logging.FileHandler(f, 'a')
    formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    fileh.setFormatter(formatter)

    log = logging.getLogger()  # root logger
    for hdlr in log.handlers[:]:  # remove all old handlers
        log.removeHandler(hdlr)
    log.addHandler(fileh)      # set the new handler

    # define a Handler which writes INFO messages or higher to the sys.stderr
    console = logging.StreamHandler()
    console.setLevel(logging.WARN)
    # set a format which is simpler for console use
    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
    # tell the handler to use this format
    console.setFormatter(formatter)
    # add the handler to the root logger
    logging.getLogger('').addHandler(console) 
Example 8
Project: screeps-stats   Author: screepers   File: screepsstats.py    License: MIT License 6 votes vote down vote up
def run(self):
        logging.basicConfig(level=logging.WARN)
        logger = logging.getLogger("ScreepsStats")
        logger.setLevel(logging.INFO)
        formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        handler = logging.FileHandler(base_directory + "/screepsstats.log")
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        websocketprocess = False
        apiprocess = False
        while True:

            if not websocketprocess or not websocketprocess.is_alive():
                websocketprocess = WebsocketProcess()
                websocketprocess.daemon = True
                websocketprocess.start()

            if not apiprocess or not apiprocess.is_alive():
                apiprocess = APIProcess()
                apiprocess.daemon = True
                apiprocess.start()

            time.sleep(3) 
Example 9
Project: insightconnect-plugins   Author: rapid7   File: mcafee.py    License: MIT License 6 votes vote down vote up
def __call__(self, *args, **kwargs):
        argmap = {}
        if len(list(args)) != 0:
            for index, value in enumerate(args):
                argmap['param' + str(index+1)] = value
        if len(list(kwargs)) != 0:
            for key in kwargs.keys():
                argmap[key] = kwargs[key]
        try:
            return self.invoker.invoke(self.prefix + '.' + self.name, argmap)
        except CommandInvokerError, e:
            if e.code == 1:
                msg = "'" + self.prefix + "' has no attribute '" + self.name + "' (make sure the command exists and that mcafee.client(...) was called prior to invoking the command)"
                log(logging.WARN, msg)
                raise AttributeError(msg)
            else:
                log(logging.ERROR, e.msg)
                raise e 
Example 10
Project: insightconnect-plugins   Author: rapid7   File: mcafee.py    License: MIT License 6 votes vote down vote up
def __getattr__(self, attr):
        """
        When the caller requests attributes that are not available, assume
        the caller wants to create a _PyCommand.  Also catch calls that dir()
        makes so we can return a list of commands
        """
        cmd = attr # for clarity...this is the command name, ie, listUsers

        #We must catch accessing __members__,__repr__, and __str__ attributes
        #otherwise it will attempt to create a PyCommand and hence hit the server
        #which we don't want.
        if cmd == '__members__':
            return # there are no members of a PyClient, only methods
        if cmd == '__methods__':
            return _get_command_names(self._invoker, self._module)
        if cmd == '__repr__':
            return # should anything be returned here?
        if cmd == '__str__':
            return # should anything be returned here?
        if cmd == '__call__':
            msg = "'" + self._module + "' object is not callable"
            log(logging.WARN, msg)
            raise TypeError(msg)
        pc = _PyCommand(self._invoker, self._module, cmd)
        return pc 
Example 11
Project: sawtooth-core   Author: hyperledger   File: main.py    License: Apache License 2.0 6 votes vote down vote up
def create_console_handler(verbose_level):
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)

    if verbose_level == 0:
        clog.setLevel(logging.WARN)
    elif verbose_level == 1:
        clog.setLevel(logging.INFO)
    else:
        clog.setLevel(logging.DEBUG)

    return clog 
Example 12
Project: sawtooth-core   Author: hyperledger   File: sawset.py    License: Apache License 2.0 6 votes vote down vote up
def create_console_handler(verbose_level):
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)

    if verbose_level == 0:
        clog.setLevel(logging.WARN)
    elif verbose_level == 1:
        clog.setLevel(logging.INFO)
    else:
        clog.setLevel(logging.DEBUG)

    return clog 
Example 13
Project: sawtooth-core   Author: hyperledger   File: sawnet.py    License: Apache License 2.0 6 votes vote down vote up
def create_console_handler(verbose_level):
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)

    if verbose_level == 0:
        clog.setLevel(logging.WARN)
    elif verbose_level == 1:
        clog.setLevel(logging.INFO)
    else:
        clog.setLevel(logging.DEBUG)

    return clog 
Example 14
Project: sawtooth-core   Author: hyperledger   File: sawadm.py    License: Apache License 2.0 6 votes vote down vote up
def create_console_handler(verbose_level):
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)

    if verbose_level == 0:
        clog.setLevel(logging.WARN)
    elif verbose_level == 1:
        clog.setLevel(logging.INFO)
    else:
        clog.setLevel(logging.DEBUG)

    return clog 
Example 15
Project: lkml   Author: joshtemple   File: __init__.py    License: MIT License 6 votes vote down vote up
def parse_args(args: Sequence) -> argparse.Namespace:
    """Parse command-line arguments."""
    parser = argparse.ArgumentParser(
        description=(
            "A blazing fast LookML parser, implemented in pure Python. "
            "When invoked from the command line, "
            "returns the parsed output as a JSON string."
        )
    )
    parser.add_argument(
        "file", type=argparse.FileType("r"), help="path to the LookML file to parse"
    )
    parser.add_argument(
        "-d",
        "--debug",
        action="store_const",
        dest="log_level",
        const=logging.DEBUG,
        default=logging.WARN,
        help="increase logging verbosity",
    )

    return parser.parse_args(args) 
Example 16
Project: lkml   Author: joshtemple   File: __init__.py    License: MIT License 6 votes vote down vote up
def cli():
    """Command-line entry point for lkml."""
    logger = logging.getLogger()
    logger.setLevel(logging.WARN)

    handler = logging.StreamHandler()
    handler.setLevel(logging.DEBUG)

    formatter = logging.Formatter("%(name)s %(levelname)s: %(message)s")

    handler.setFormatter(formatter)
    logger.addHandler(handler)

    args = parse_args(sys.argv[1:])

    logging.getLogger().setLevel(args.log_level)

    lookml = load(args.file)
    args.file.close()

    json_string = json.dumps(lookml, indent=2)
    print(json_string) 
Example 17
Project: spider   Author: shancang   File: common.py    License: Apache License 2.0 6 votes vote down vote up
def set_log(level, filename='spider.log'):
    """
    return a log file object
    根据提示设置log打印
    """
    if not os.path.isdir(LOG_DIR):
    	os.mkdir(LOG_DIR)
    log_file = os.path.join(LOG_DIR, filename)
    if not os.path.isfile(log_file):
        os.mknod(log_file)
        os.chmod(log_file, 0777)
    log_level_total = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARN, 'error': logging.ERROR,
                       'critical': logging.CRITICAL}
    logger_f = logging.getLogger('spider')
    logger_f.setLevel(logging.DEBUG)
    fh = logging.FileHandler(log_file,'a')
    fh.setLevel(log_level_total.get(level, logging.DEBUG))
    formatter = logging.Formatter('%(asctime)s  %(filename)s  [line:%(lineno)d] %(levelname)s  %(message)s')
    fh.setFormatter(formatter)
    logger_f.addHandler(fh)
    keep_fds = [fh.stream.fileno()]
    return logger_f,keep_fds 
Example 18
Project: lockebot   Author: nmstoker   File: util.py    License: MIT License 6 votes vote down vote up
def setup_custom_logger(name):
    formatter = logging.Formatter(
        STY_DESC_DEBUG + '%(asctime)s - %(module)s - %(levelname)8s - %(message)s' +
            style.RESET, datefmt='%Y-%b-%d %H:%M:%S')

    handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    logger = logging.getLogger(name)
    logger.setLevel(logging.WARN)
    logger.addHandler(handler)
    return logger

    # self.logger = logging.getLogger(self.BOTNAME)
    # self.logger.setLevel(logging.DEBUG)

    # self.ch.setLevel(logging.WARN)
    # # ch.setLevel(logging.DEBUG)
    # self.ch.setFormatter(self.formatter)
    # self.logger.addHandler(self.ch) 
Example 19
Project: DSTC6-End-to-End-Conversation-Modeling   Author: dialogtekgeek   File: tqdm_logging.py    License: MIT License 6 votes vote down vote up
def config(logger, logfile='', mode='w', silent=False, debug=False,
           format="%(asctime)s %(levelname)s %(message)s"):

    #logger = logging.getLogger("root")

    if silent:
        level = logging.WARN
    else:
        level = logging.INFO

    stdhandler = TqdmLoggingHandler(level=level)
    stdhandler.setFormatter(logging.Formatter(format))
    logger.addHandler(stdhandler)

    if logfile:
        filehandler = logging.FileHandler(logfile, mode=mode)
        filehandler.setFormatter(logging.Formatter(format))
        logger.addHandler(filehandler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger 
Example 20
Project: DSTC6-End-to-End-Conversation-Modeling   Author: dialogtekgeek   File: tqdm_logging.py    License: MIT License 6 votes vote down vote up
def config(logger, logfile='', mode='w', silent=False, debug=False,
           format="%(asctime)s %(levelname)s %(message)s"):

    #logger = logging.getLogger("root")

    if silent:
        level = logging.WARN
    else:
        level = logging.INFO

    stdhandler = TqdmLoggingHandler(level=level)
    stdhandler.setFormatter(logging.Formatter(format))
    logger.addHandler(stdhandler)

    if logfile:
        filehandler = logging.FileHandler(logfile, mode=mode)
        filehandler.setFormatter(logging.Formatter(format))
        logger.addHandler(filehandler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger 
Example 21
Project: DSTC6-End-to-End-Conversation-Modeling   Author: dialogtekgeek   File: tqdm_logging.py    License: MIT License 6 votes vote down vote up
def config(logger, logfile='', mode='w', silent=False, debug=False,
           format="%(asctime)s %(levelname)s %(message)s"):

    #logger = logging.getLogger("root")

    if silent:
        level = logging.WARN
    else:
        level = logging.INFO

    stdhandler = TqdmLoggingHandler(level=level)
    stdhandler.setFormatter(logging.Formatter(format))
    logger.addHandler(stdhandler)

    if logfile:
        filehandler = logging.FileHandler(logfile, mode=mode)
        filehandler.setFormatter(logging.Formatter(format))
        logger.addHandler(filehandler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger 
Example 22
Project: DSTC6-End-to-End-Conversation-Modeling   Author: dialogtekgeek   File: tqdm_logging.py    License: MIT License 6 votes vote down vote up
def config(logger, logfile='', mode='w', silent=False, debug=False,
           format="%(asctime)s %(levelname)s %(message)s"):

    #logger = logging.getLogger("root")

    if silent:
        level = logging.WARN
    else:
        level = logging.INFO

    stdhandler = TqdmLoggingHandler(level=level)
    stdhandler.setFormatter(logging.Formatter(format))
    logger.addHandler(stdhandler)

    if logfile:
        filehandler = logging.FileHandler(logfile, mode=mode)
        filehandler.setFormatter(logging.Formatter(format))
        logger.addHandler(filehandler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger 
Example 23
Project: learning2run   Author: AdamStelmaszczyk   File: run_mujoco.py    License: MIT License 6 votes vote down vote up
def train(env_id, num_timesteps, seed):
    whoami  = mpi_fork(num_cpu)
    if whoami == "parent":
        return
    import baselines.common.tf_util as U
    logger.session().__enter__()
    sess = U.single_threaded_session()
    sess.__enter__()

    rank = MPI.COMM_WORLD.Get_rank()
    if rank != 0:
        logger.set_level(logger.DISABLED)
    workerseed = seed + 10000 * MPI.COMM_WORLD.Get_rank()
    set_global_seeds(workerseed)
    env = gym.make(env_id)
    def policy_fn(name, ob_space, ac_space):
        return MlpPolicy(name=name, ob_space=env.observation_space, ac_space=env.action_space,
            hid_size=32, num_hid_layers=2)
    env = bench.Monitor(env, osp.join(logger.get_dir(), "%i.monitor.json" % rank))
    env.seed(workerseed)
    gym.logger.setLevel(logging.WARN)

    trpo_mpi.learn(env, policy_fn, timesteps_per_batch=1024, max_kl=0.01, cg_iters=10, cg_damping=0.1,
        max_timesteps=num_timesteps, gamma=0.99, lam=0.98, vf_iters=5, vf_stepsize=1e-3)
    env.close() 
Example 24
Project: learning2run   Author: AdamStelmaszczyk   File: run_mujoco.py    License: MIT License 6 votes vote down vote up
def train(env_id, num_timesteps, seed):
    from baselines.pposgd import mlp_policy, pposgd_simple
    U.make_session(num_cpu=1).__enter__()
    logger.session().__enter__()
    set_global_seeds(seed)
    env = gym.make(env_id)
    def policy_fn(name, ob_space, ac_space):
        return mlp_policy.MlpPolicy(name=name, ob_space=ob_space, ac_space=ac_space,
            hid_size=64, num_hid_layers=2)
    env = bench.Monitor(env, osp.join(logger.get_dir(), "monitor.json"))
    env.seed(seed)
    gym.logger.setLevel(logging.WARN)
    pposgd_simple.learn(env, policy_fn, 
            max_timesteps=num_timesteps,
            timesteps_per_batch=2048,
            clip_param=0.2, entcoeff=0.0,
            optim_epochs=10, optim_stepsize=3e-4, optim_batchsize=64,
            gamma=0.99, lam=0.95,
        )
    env.close() 
Example 25
Project: drydock   Author: airshipit   File: base.py    License: Apache License 2.0 5 votes vote down vote up
def warn(self, ctx, msg):
        self.log_error(ctx, logging.WARN, msg) 
Example 26
Project: cs294-112_hws   Author: xuwd11   File: logger.py    License: MIT License 5 votes vote down vote up
def _get_logger(self, name, log_path, lvl=logging.INFO, display_name=None):
        if isinstance(lvl, str):
            lvl = lvl.lower().strip()
            if lvl == 'debug':
                lvl = logging.DEBUG
            elif lvl == 'info':
                lvl = logging.INFO
            elif lvl == 'warn' or lvl == 'warning':
                lvl = logging.WARN
            elif lvl == 'error':
                lvl = logging.ERROR
            elif lvl == 'fatal' or lvl == 'critical':
                lvl = logging.CRITICAL
            else:
                raise ValueError('unknown logging level')

        file_handler = logging.FileHandler(log_path)
        file_handler.setLevel(logging.DEBUG)
        file_handler.setFormatter(LoggerClass._normal_formatter)
        console_handler = logging.StreamHandler()
        console_handler.setLevel(lvl)
        console_handler.setFormatter(LoggerClass._color_formatter)
        if display_name is None:
            display_name = name
        logger = logging.getLogger(display_name)
        logger.setLevel(logging.DEBUG)
        logger.addHandler(console_handler)
        logger.addHandler(file_handler)

        return logger

    ###############
    ### Logging ###
    ############### 
Example 27
Project: lirpg   Author: Hwhitetooth   File: behavior_clone.py    License: MIT License 5 votes vote down vote up
def main(args):
    U.make_session(num_cpu=1).__enter__()
    set_global_seeds(args.seed)
    env = gym.make(args.env_id)

    def policy_fn(name, ob_space, ac_space, reuse=False):
        return mlp_policy.MlpPolicy(name=name, ob_space=ob_space, ac_space=ac_space,
                                    reuse=reuse, hid_size=args.policy_hidden_size, num_hid_layers=2)
    env = bench.Monitor(env, logger.get_dir() and
                        osp.join(logger.get_dir(), "monitor.json"))
    env.seed(args.seed)
    gym.logger.setLevel(logging.WARN)
    task_name = get_task_name(args)
    args.checkpoint_dir = osp.join(args.checkpoint_dir, task_name)
    args.log_dir = osp.join(args.log_dir, task_name)
    dataset = Mujoco_Dset(expert_path=args.expert_path, traj_limitation=args.traj_limitation)
    savedir_fname = learn(env,
                          policy_fn,
                          dataset,
                          max_iters=args.BC_max_iter,
                          ckpt_dir=args.checkpoint_dir,
                          log_dir=args.log_dir,
                          task_name=task_name,
                          verbose=True)
    avg_len, avg_ret = runner(env,
                              policy_fn,
                              savedir_fname,
                              timesteps_per_batch=1024,
                              number_trajs=10,
                              stochastic_policy=args.stochastic_policy,
                              save=args.save_sample,
                              reuse=True) 
Example 28
Project: HardRLWithYoutube   Author: MaxSobolMark   File: behavior_clone.py    License: MIT License 5 votes vote down vote up
def main(args):
    U.make_session(num_cpu=1).__enter__()
    set_global_seeds(args.seed)
    env = gym.make(args.env_id)

    def policy_fn(name, ob_space, ac_space, reuse=False):
        return mlp_policy.MlpPolicy(name=name, ob_space=ob_space, ac_space=ac_space,
                                    reuse=reuse, hid_size=args.policy_hidden_size, num_hid_layers=2)
    env = bench.Monitor(env, logger.get_dir() and
                        osp.join(logger.get_dir(), "monitor.json"))
    env.seed(args.seed)
    gym.logger.setLevel(logging.WARN)
    task_name = get_task_name(args)
    args.checkpoint_dir = osp.join(args.checkpoint_dir, task_name)
    args.log_dir = osp.join(args.log_dir, task_name)
    dataset = Mujoco_Dset(expert_path=args.expert_path, traj_limitation=args.traj_limitation)
    savedir_fname = learn(env,
                          policy_fn,
                          dataset,
                          max_iters=args.BC_max_iter,
                          ckpt_dir=args.checkpoint_dir,
                          log_dir=args.log_dir,
                          task_name=task_name,
                          verbose=True)
    avg_len, avg_ret = runner(env,
                              policy_fn,
                              savedir_fname,
                              timesteps_per_batch=1024,
                              number_trajs=10,
                              stochastic_policy=args.stochastic_policy,
                              save=args.save_sample,
                              reuse=True) 
Example 29
Project: ciftify   Author: edickie   File: cifti_vis_PINT.py    License: MIT License 5 votes vote down vote up
def main():
    global DEBUG
    arguments  = docopt(__doc__)
    snaps      = arguments['subject'] or arguments['snaps']
    index      = arguments['index']
    verbose    = arguments['--verbose']
    DEBUG      = arguments['--debug']

    if arguments['snaps']:
        logger.warning("The 'snaps' argument has be deprecated. Please use 'subject' in the future.")

    if verbose:
        logger.setLevel(logging.INFO)
        # Also set level for all loggers in ciftify module (or else will be
        # logging.WARN by default)
        logging.getLogger('ciftify').setLevel(logging.INFO)
    if DEBUG:
        logger.setLevel(logging.DEBUG)
        logging.getLogger('ciftify').setLevel(logging.DEBUG)

    ciftify.utils.log_arguments(arguments)

    settings = UserSettings(arguments)
    qc_config = ciftify.qc_config.Config(settings.qc_mode)

    ## make pics and qcpage for each subject
    if snaps:
        with ciftify.utils.TempDir() as temp_dir:
            logger.debug('Created tempdir {} on host {}'.format(temp_dir,
                    os.uname()[1]))
            logger.info("Making snaps for subject: {}".format(
                    settings.subject))
            ret = run_snaps(settings, qc_config, temp_dir, temp_dir)
        return ret

    # Start the index html file
    if index:
        logger.info("Writing Index pages to: {}".format(settings.qc_dir))
        ret = write_all_index_pages(settings, qc_config)
        return ret 
Example 30
Project: multicast-relay   Author: alsmith   File: multicast-relay.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, foreground, logfile, verbose):
        self.verbose = verbose

        try:
            import logging
            import logging.handlers
            self.loggingAvailable = True

            logger = logging.getLogger()
            syslog_handler = logging.handlers.SysLogHandler()
            syslog_handler.setFormatter(logging.Formatter(fmt='%(name)s[%(process)d] %(levelname)s: %(message)s'))
            logger.addHandler(syslog_handler)

            if foreground:
                stream_handler = logging.StreamHandler(sys.stdout)
                stream_handler.setFormatter(logging.Formatter(fmt='%(asctime)s %(name)s %(levelname)s: %(message)s', datefmt='%b-%d %H:%M:%S'))
                logger.addHandler(stream_handler)

            if logfile:
                file_handler = logging.FileHandler(logfile)
                file_handler.setFormatter(logging.Formatter(fmt='%(asctime)s %(name)s %(levelname)s: %(message)s', datefmt='%b-%d %H:%M:%S'))
                logger.addHandler(file_handler)

            if verbose:
                logger.setLevel(logging.INFO)
            else:
                logger.setLevel(logging.WARN)

        except ImportError:
            self.loggingAvailable = False