當前位置: 首頁>>代碼示例>>Python>>正文


Python logger.log方法代碼示例

本文整理匯總了Python中logger.log方法的典型用法代碼示例。如果您正苦於以下問題:Python logger.log方法的具體用法?Python logger.log怎麽用?Python logger.log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在logger的用法示例。


在下文中一共展示了logger.log方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def __init__(self, params):
        configure_logger(params['output_dir'])
        log('Parameters {}'.format(params))
        self.params = params
        self.binding = load_bindings(params['rom_file_path'])
        self.max_word_length = self.binding['max_word_length']
        self.sp = spm.SentencePieceProcessor()
        self.sp.Load(params['spm_file'])
        kg_env = KGA2CEnv(params['rom_file_path'], params['seed'], self.sp,
                          params['tsv_file'], step_limit=params['reset_steps'],
                          stuck_steps=params['stuck_steps'], gat=params['gat'])
        self.vec_env = VecEnv(params['batch_size'], kg_env, params['openie_path'])
        self.template_generator = TemplateActionGenerator(self.binding)
        env = FrotzEnv(params['rom_file_path'])
        self.vocab_act, self.vocab_act_rev = load_vocab(env)
        self.model = KGA2C(params, self.template_generator.templates, self.max_word_length,
                           self.vocab_act, self.vocab_act_rev, len(self.sp), gat=self.params['gat']).cuda()
        self.batch_size = params['batch_size']
        if params['preload_weights']:
            self.model = torch.load(self.params['preload_weights'])['model']
        self.optimizer = optim.Adam(self.model.parameters(), lr=params['lr'])

        self.loss_fn1 = nn.BCELoss()
        self.loss_fn2 = nn.BCEWithLogitsLoss()
        self.loss_fn3 = nn.MSELoss() 
開發者ID:rajammanabrolu,項目名稱:KG-A2C,代碼行數:27,代碼來源:gdqn.py

示例2: convertImgurIndirectUrlToImg

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def convertImgurIndirectUrlToImg(submission, imgurAuth, url):
    # Login to imgur
    # This is required since they made NSFW images require login
    imgurClient = imgur.ImgurClient(imgurAuth.clientId, imgurAuth.clientSecret)

    if not checkImgurAPICredits(imgurClient):
        return None

    imageId = imgurIdFromUrl(url)
    if not imageId:
        logger.log("Failed to convert {} to image id".format(url))
        
    try:
        return imgurClient.get_image(imageId).link
    except Exception as e:
        errorMessage = ('Failed to convert imgur to image link: '
                        '[ERROR] Exception: Url {} raised exception:\n\t {}'.format(url, e))
        logger.log(errorMessage)
        LikedSavedDatabase.db.addUnsupportedSubmission(submission, errorMessage)
        return None 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:22,代碼來源:imgurDownloader.py

示例3: checkImgurAPICredits

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def checkImgurAPICredits(imgurClient):
    logger.log('Imgur API Credit Report:\n'
        + '\tUserRemaining: ' + str(imgurClient.credits['UserRemaining'])
        + '\n\tClientRemaining: ' + str(imgurClient.credits['ClientRemaining']))

    if not imgurClient.credits['UserRemaining']:
        logger.log('You have used up all of your Imgur API credits! Please wait an hour')
        return False

    # Ensure that this user doesn't suck up all the credits (remove this if you're an asshole)
    if imgurClient.credits['ClientRemaining'] < 1000:
        logger.log('RedditLikedSavedImageDownloader Imgur Client is running low on Imgur API credits!\n'
            'Unfortunately, this means no one can download any Imgur albums until the end of the month.\n'
            'If you are really jonesing for access, authorize your own Imgur Client and fill in'
            ' its details in settings.txt.')
        return False

    return True 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:20,代碼來源:imgurDownloader.py

示例4: getUrlContentType

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def getUrlContentType(url):
    if url:
        openedUrl = None
        try:
            openedUrl = urlopen(url)
        except IOError as e:
            logger.log('[ERROR] getUrlContentType(): IOError: Url {0} raised exception:\n\t{1} {2}'
                .format(url, e.errno, e.strerror))
        except Exception as e:
            logger.log('[ERROR] Exception: Url {0} raised exception:\n\t {1}'
                        .format(url, e))
            logger.log('[ERROR] Url ' + url + 
                ' raised an exception I did not handle. Open an issue at '
                '\n\thttps://github.com/makuto/redditLikedSavedImageDownloader/issues'
                '\n and I will try to fix it')
        else:
            if sys.version_info[0] >= 3:
                return openedUrl.info().get_content_subtype()
            else:
                return openedUrl.info().subtype
    return '' 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:23,代碼來源:imageSaver.py

示例5: main

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def main(args, extra_args, save_path):
    # configure logger, disable logging in child MPI processes (with rank > 0)

    # arg_parser = common_arg_parser()
    # args, unknown_args = arg_parser.parse_known_args()
    # extra_args = parse_cmdline_kwargs(unknown_args)

    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure()
    else:
        logger.configure(format_strs=[])
        rank = MPI.COMM_WORLD.Get_rank()

    model, env = train(args, extra_args)
    # env.close()

    # if args.save_path is not None and rank == 0:
    #     save_path = osp.expanduser(args.save_path)
    model.save(save_path)

    if args.play:
        logger.log("Running trained model")
        print()
        # env = build_env(args)
        obs = env.reset()
        def initialize_placeholders(nlstm=128,**kwargs):
            return np.zeros((args.num_env or 1, 2*nlstm)), np.zeros((1))
        state, dones = initialize_placeholders(**extra_args)
        while True:
            actions, _, state, _ = model.step(obs,S=state, M=dones)
            obs, _, done, _ = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset()

        env.close() 
開發者ID:quantumiracle,項目名稱:Reinforcement_Learning_for_Traffic_Light_Control,代碼行數:41,代碼來源:run.py

示例6: main

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def main(args, extra_args, save_path):
    # configure logger, disable logging in child MPI processes (with rank > 0)

    # arg_parser = common_arg_parser()
    # args, unknown_args = arg_parser.parse_known_args()
    # extra_args = parse_cmdline_kwargs(unknown_args)

    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure()
    else:
        logger.configure(format_strs=[])
        rank = MPI.COMM_WORLD.Get_rank()

    model, env = train(args, extra_args)
    # env.close()

    # if args.save_path is not None and rank == 0:
    #     save_path = osp.expanduser(args.save_path)
    model.save(save_path)

    if args.play:
        logger.log("Running trained model")
        print()
        # env = build_env(args)
        obs = env.reset()
        def initialize_placeholders(nlstm=128,**kwargs):
            return np.zeros((args.num_env or 1, 2*nlstm)), np.zeros((1))
        state, dones = initialize_placeholders(**extra_args)
        while True:
            actions, _, state, _ = model.step(obs,S=state, M=dones)
            obs, _, done, _ = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset()

        # env.close() 
開發者ID:quantumiracle,項目名稱:Reinforcement_Learning_for_Traffic_Light_Control,代碼行數:41,代碼來源:run.py

示例7: configure_logger

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def configure_logger(log_dir):
    logger.configure(log_dir, format_strs=['log'])
    global tb
    tb = logger.Logger(log_dir, [logger.make_output_format('tensorboard', log_dir),
                                 logger.make_output_format('csv', log_dir),
                                 logger.make_output_format('stdout', log_dir)])
    global log
    log = logger.log 
開發者ID:rajammanabrolu,項目名稱:KG-A2C,代碼行數:10,代碼來源:gdqn.py

示例8: __parse

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def __parse(self, lines):
        #log("FieldNode: " + line + " parsing")
        self.buf = lines

        i = self.buf[0].find('=')
        segs = []
        if i > 0:
            segs = self.buf[0][:i].split()
            self.value = self.buf[0][i + 1:].strip()
        else:
            segs = self.buf[0].split()
        self.access = segs[1:-1]
        self.name, self.descriptor = segs[-1].split(':')
        log("FieldNode: " + self.name + " parsed!") 
開發者ID:pilgun,項目名稱:acvtool,代碼行數:16,代碼來源:fieldnode.py

示例9: _log_rc

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def _log_rc(cmd_output, funct_name, **kvarg):
    """Generic logger that picks correct log type based on return code"""

    rc = cmd_output['rc'] if 'rc' in cmd_output else cmd_output

    logger.log(logger.decide_level(rc),
               funct_name,
               **kvarg
               ) 
開發者ID:Bridgewater,項目名稱:appetite,代碼行數:11,代碼來源:conn_manager.py

示例10: AddAllFromReddit

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def AddAllFromReddit(database, settings):
    if not settings.hasRedditSettings():
        logger.log('Reddit settings are not provided!')
        return

    submissions = []

    logger.log('Adding last 1000 liked/saved submissions from Reddit. This will take a long time.')

    redditSubmissions, redditComments, earlyOutPoints = redditScraper.getRedditUserLikedSavedSubmissions(
        settings.settings['Username'], settings.settings['Password'], 
        settings.settings['Client_id'], settings.settings['Client_secret'],
        request_limit = None, # No limit = request as many as possible (1000)
        saveLiked = settings.settings['Reddit_Save_Liked'], 
        saveSaved = settings.settings['Reddit_Save_Saved'],
        earlyOutPointSaved = None, 
        earlyOutPointLiked = None,
        unlikeLiked = False,
        unsaveSaved = False)

    logger.log('Retrieved submissions, adding to database...')

    for submission in redditSubmissions:
        database.addSubmission(submission)

    for comment in redditComments:
        database.addComment(comment)

    logger.log('Done! Saved {} submissions and {} comments'.format(len(redditSubmissions), len(redditComments))) 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:31,代碼來源:CreateDatabase.py

示例11: AddAllFromDirectory

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def AddAllFromDirectory(fileDatabase, directory):
    logger.log('Scanning {} to create FileCollectionDatabase'.format(directory))
    numFiles = 0
    for root, dirs, files in os.walk(directory):
        for file in files:
            fileDatabase.addFileNoSave(file, os.path.relpath(os.path.join(root, file), directory))
            numFiles += 1
            
    fileDatabase.save()

    logger.log('Done; {} files in database'.format(numFiles)) 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:13,代碼來源:CreateDatabase.py

示例12: initialize

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def initialize():
    settings.getSettings()
        
    if not settings.settings['Database']:
        logger.log('Please provide a location for the Database')
        return

    # Do this early so we can use it anywhere
    LikedSavedDatabase.initializeFromSettings(settings.settings) 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:11,代碼來源:redditUserImageScraper.py

示例13: saveRequestedUrls

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def saveRequestedUrls(pipeConnection, urls):
    if pipeConnection:
        logger.setPipe(pipeConnection)

    initialize()

    logger.log('Attempting to save {} requested urls. This may take several minutes...'
               .format(len(urls)))

    submissions = []
    # Create Submission for each URL
    for url in urls:
        convertedSubmission = submission.Submission()
        convertedSubmission.source = "UserRequested"
        convertedSubmission.title = "UserRequested"
        convertedSubmission.author = "(Requested by user)"
        convertedSubmission.subreddit = "Requested_Downloads"
        convertedSubmission.subredditTitle = "Requested Downloads"
        convertedSubmission.body = "(Requested by user)"
        convertedSubmission.bodyUrl= url
        convertedSubmission.postUrl= url
        submissions.append(convertedSubmission)

    if len(submissions) != len(urls):
        logger.log('Could not parse {} URLs!'.format(len(urls) - len(submissions)))

    unsupportedSubmissions = imageSaver.saveAllImages(settings.settings['Output_dir'], submissions, 
                                                      imgur_auth = imgurDownloader.getImgurAuth(),
                                                      only_download_albums = settings.settings['Only_download_albums'],
                                                      skip_n_percent_submissions = settings.settings['Skip_n_percent_submissions'],
                                                      soft_retrieve_imgs = settings.settings['Should_soft_retrieve'],
                                                      only_important_messages = settings.settings['Only_important_messages'])

    logger.log('Download finished. Output to \'Requested Downloads\' directory')
    
    if pipeConnection:
        logger.log(scriptFinishedSentinel)
        pipeConnection.close() 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:40,代碼來源:redditUserImageScraper.py

示例14: getImgurAuth

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def getImgurAuth():
    imgurAuth = None
    if settings.hasImgurSettings():
        return ImgurAuth(settings.settings['Imgur_client_id'], 
                                         settings.settings['Imgur_client_secret'])
    else:
        logger.log('No Imgur Client ID and/or Imgur Client Secret was provided, or album download is not'
                   ' enabled. This is required to download imgur albums. They will be ignored. Check'
                   ' settings.txt for how to fill in these values.')
        return None 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:12,代碼來源:imgurDownloader.py

示例15: gfycatToRedGifsWorkaround

# 需要導入模塊: import logger [as 別名]
# 或者: from logger import log [as 別名]
def gfycatToRedGifsWorkaround(gfyUrl):
    logger.log("Using Gfycat->RedGifs workaround")
    return findSourceFromHTML(gfyUrl, '<source id="mp4source" src=')

# Lazy initialize in case it's not needed 
開發者ID:makuto,項目名稱:Liked-Saved-Image-Downloader,代碼行數:7,代碼來源:imageSaver.py


注:本文中的logger.log方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。