微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python logging 模块-verbose() 实例源码

Python logging 模块,verbose() 实例源码

我们从Python开源项目中,提取了以下26代码示例,用于说明如何使用logging.verbose()

项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def init_logger(self, args):
        level = logging.INFO
        if args.verbose:
            level = logging.VERBOSE
        if args.debug:
            level = logging.DEBUG
        logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
                            level=level)

        Rthandler = RotatingFileHandler('arbitrage.log', maxBytes=100*1024*1024,backupCount=10)
        Rthandler.setLevel(level)
        formatter = logging.Formatter('%(asctime)-12s [%(levelname)s] %(message)s')  
        Rthandler.setFormatter(formatter)
        logging.getLogger('').addHandler(Rthandler)

        logging.getLogger("requests").setLevel(logging.WARNING)
        logging.getLogger("urllib3").setLevel(logging.WARNING)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def main(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("-d", "--debug", help="debug verbose mode",
                            action="store_true")
        parser.add_argument("-v", "--verbose", help="info verbose mode",
                            action="store_true")
        parser.add_argument("-o", "--observers", type=str,
                            help="observers,example: -oLogger,Emailer")
        parser.add_argument("-m", "--markets",
                            help="markets,example: -mHaobtcCNY,Bitstamp")
        parser.add_argument("-s", "--status", help="status", action="store_true")
        parser.add_argument("command", nargs='*', default="watch",
                            help='verb: "watch|replay-history|get-balance|list-public-markets|get-broker-balance"')
        args = parser.parse_args()
        self.init_logger(args)
        self.exec_command(args)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def init_logger(self,backupCount=10)
        Rthandler.setLevel(level)
        formatter = logging.Formatter('%(asctime)-12s [%(levelname)s] %(message)s')  
        Rthandler.setFormatter(formatter)
        logging.getLogger('').addHandler(Rthandler)

        logging.getLogger("requests").setLevel(logging.WARNING)
        logging.getLogger("urllib3").setLevel(logging.WARNING)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def main(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("-d",
                            help='verb: "watch|replay-history|get-balance|list-public-markets|get-broker-balance"')
        args = parser.parse_args()
        self.init_logger(args)
        self.exec_command(args)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE")
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def buy(self, amount, price, client_id=None):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, "CNY", self.currency)
        logging.verbose("Buy %f BTC at %f %s (%f CNY) @%s" % (amount,
                     local_currency_price, self.currency, self.name))
        if client_id:
            return self._buy(amount, local_currency_price, client_id)
        else:
            return self._buy(amount, local_currency_price)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def sell(self, self.currency)
        logging.verbose("Sell %f BTC at %f %s (%f CNY) @%s" % (amount, self.name))
        if client_id:
            return self._sell(amount, client_id)
        else:
            return self._sell(amount, local_currency_price)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def sell_maker(self, price):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, self.currency)
        local_currency_price = int(local_currency_price)

        logging.verbose("Sell maker %f BTC at %d %s (%d CNY) @%s" % (amount, self.name))

        return self._sell_maker(amount, local_currency_price)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker()))
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, "VERBOSE")
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def init_logger(self,
                            level=level)
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def main(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("-d",example: -mMtGox,Bitstamp")
        parser.add_argument("command",
                            help='verb: "watch|replay-history|get-balance|list-public-markets"')
        args = parser.parse_args()
        self.init_logger(args)
        self.exec_command(args)
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def opportunity(self, profit, volume, buyprice, kask, sellprice, kbid, perc,
                    weighted_buyprice, weighted_sellprice):
        if profit < config.profit_thresh or perc < config.perc_thresh:
            logging.verbose("[TraderBot] Profit or profit percentage lower than"+
                            " thresholds")
            return
        if kask not in self.clients:
            logging.warn("[TraderBot] Can't automate this Trade,client not "+
                         "available: %s" % kask)
            return
        if kbid not in self.clients:
            logging.warn("[TraderBot] Can't automate this Trade," +
                         "client not available: %s" % kbid)
            return
        volume = min(config.max_tx_volume, volume)

        # Update client balance
        self.update_balance()
        max_volume = self.get_min_Tradeable_volume(buyprice,
                                                   self.clients[kask].usd_balance,
                                                   self.clients[kbid].btc_balance)
        volume = min(volume, max_volume, config.max_tx_volume)
        if volume < config.min_tx_volume:
            logging.warn("Can't automate this Trade,minimum volume transaction"+
                         " not reached %f/%f" % (volume, config.min_tx_volume))
            logging.warn("Balance on %s: %f USD - Balance on %s: %f BTC"
                         % (kask, self.clients[kask].usd_balance,
                            self.clients[kbid].btc_balance))
            return
        current_time = time.time()
        if current_time - self.last_Trade < self.Trade_wait:
            logging.warn("[TraderBot] Can't automate this Trade,last Trade " +
                         "occured %.2f seconds ago" %
                         (current_time - self.last_Trade))
            return
        self.potential_Trades.append([profit,
                                      weighted_buyprice, weighted_sellprice,
                                      buyprice, sellprice])
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker()))
项目:salicapi    作者:Lafaiet    | 项目源码 | 文件源码
def instantiate( cls, streamType = "SCREEN", logLevel = "INFO" ):
        try:
            logging.VERBOSE = 5
            logging.addLevelName(logging.VERBOSE, "VERBOSE")
            logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, **kwargs)
            logging.verbose = lambda msg, **kwargs: logging.log(logging.VERBOSE, **kwargs)

            cls.logger = logging.getLogger()

            if logLevel not in logging._levelNames:
                raise Exception( 'Invalid file level' )

            cls.logger.setLevel( logging._levelNames[logLevel] )

            streamType = app.config['STREAMTYPE']

            if streamType == "SCREEN":
                stream = logging.StreamHandler()
            else:
                stream = logging.FileHandler( app.config['LOGFILE'] )

            formatter = logging.Formatter( '[%(levelname)-7s - %(asctime)s] %(message)s' )
            stream.setFormatter( formatter )
            cls.logger.addHandler( stream )
        except Exception, e:
            print( 'Unable to get/set log configurations. Error: %s'%( e ) )
            cls.logger = None


    ##
    # Records a message in a file and/or displays it in the screen.
    # @param level - String containing the name of the log message.
    # @param message - String containing the message to be recorded.
    #
项目:salicapi    作者:Lafaiet    | 项目源码 | 文件源码
def verbose( cls, message ):
        cls.log("VERBOSE", message, Log.getCallers( inspect.stack() ))

    ##
    # Gets the data about the caller of the log method.
    # @param stack Array containing the system calling stack.
    # @return Array containing the caller class name and the caller method,respectively.
    #
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, "VERBOSE")
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def buy(self, local_currency_price)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def sell(self, local_currency_price)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def sell_maker(self, local_currency_price)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker()))
项目:kobo    作者:release-engineering    | 项目源码 | 文件源码
def test_verbose_hack(self):
        self.logger.verbose("foo")
        logging.verbose("foo")
        self.assertEqual(logging.VERBOSE, 15)
        if six.PY2:
            # There is no _levelNames attribute in Python 3
            self.assertTrue("VERBOSE" in logging._levelNames)
        self.assertEqual(logging.getLevelName(15), "VERBOSE")
项目:kobo    作者:release-engineering    | 项目源码 | 文件源码
def verbose(self, **kwargs):
    """
    Log 'msg % args' with severity 'VERBOSE'.

    To pass exception information,use the keyword argument exc_info with
    a true value,e.g.

    logger.info("Houston,we have a %s","interesting problem",exc_info=1)
    """
    if self.manager.disable >= logging.VERBOSE:
        return
    if logging.VERBOSE >= self.getEffectiveLevel():
        self._log(*(logging.VERBOSE, args), **kwargs)
项目:kobo    作者:release-engineering    | 项目源码 | 文件源码
def verbose(msg, **kwargs):
    """
    Log a message with severity 'VERBOSE' on the root logger.
    """
    if len(logging.root.handlers) == 0:
        logging.basicConfig()
    logging.root.verbose(*((msg, ) + args), **kwargs)
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def new_order(self, kexchange, type, maker_only=True, amount=None, price=None):
        if type == 'buy' or type == 'sell':
            if not price or not amount:
                if type == 'buy':
                    price = self.get_buy_price()
                    amount = math.floor((self.cny_balance/price)*10)/10
                else:
                    price = self.get_sell_price()
                    amount = math.floor(self.btc_balance * 10) / 10

            if maker_only:
                amount = min(self.max_maker_volume, amount)
                if amount < self.min_maker_volume:
                    logging.debug('Maker amount is too low %s %s' % (type, amount))
                    return None
            else:
                amount = min(self.max_taker_volume, amount)
                if amount < self.min_taker_volume:
                    logging.debug('Taker amount is too low %s %s' % (type, amount))
                    return None

            if maker_only:                
                if type == 'buy':
                    order_id = self.clients[kexchange].buy_maker(amount, price)
                else:
                    order_id = self.clients[kexchange].sell_maker(amount, price)
            else:
                if type == 'buy':
                    order_id = self.clients[kexchange].buy(amount, price)
                else:
                    order_id = self.clients[kexchange].sell(amount, price)

            if not order_id:
                logging.warn("%s @%s %f/%f BTC Failed" % (type, price))
                return None

            if order_id == -1:
                logging.warn("%s @%s %f/%f BTC Failed,%s" % (type, order_id))
                return None

            order = {
                'market': kexchange, 
                'id': order_id,
                'price': price,
                'amount': amount,
                'deal_amount':0,
                'deal_index': 0, 
                'type': type,
                'maker_only': maker_only,
                'time': time.time()
            }
            self.orders.append(order)
            logging.verbose("submit order %s" % (order))

            return order

        return None
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def new_order(self, amount)
                if amount < self.min_maker_volume:
                    logging.warn('Maker amount is too low %s %s' % (type, amount)
                if amount < self.min_taker_volume:
                    logging.warn('Taker amount is too low %s %s' % (type, price)

            if not order_id:
                logging.warn("%s @%s %f/%f BTC Failed, order_id))
                return None

            if order_id == -1:
                logging.warn("%s @%s %f/%f BTC Failed,
                'time': time.time()
            }
            self.orders.append(order)
            logging.verbose("submit order %s" % (order))

            return order

        return None

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐