Python logging.verbose() Examples

The following are code examples for showing how to use logging.verbose(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: bitcoin-arbitrage   Author: ucfyao   File: arbitrage.py    (license) View Source Project 9 votes vote down vote up
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) 
Example 2
Project: bitcoin-arbitrage   Author: ucfyao   File: arbitrage.py    (license) View Source Project 6 votes vote down vote up
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", type=str,
                            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) 
Example 3
Project: crypto-arbitrager   Author: artooze   File: arbitrage.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 4
Project: crypto-arbitrager   Author: artooze   File: arbitrage.py    (license) View Source Project 6 votes vote down vote up
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", type=str,
                            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) 
Example 5
Project: bitcoin-arbitrage   Author: ucfyao   File: arbitrage.py    (license) View Source Project 5 votes vote down vote up
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE") 
Example 6
Project: bitcoin-arbitrage   Author: ucfyao   File: market.py    (license) View Source Project 5 votes vote down vote up
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, price, self.name))
        if client_id:
            return self._buy(amount, local_currency_price, client_id)
        else:
            return self._buy(amount, local_currency_price) 
Example 7
Project: bitcoin-arbitrage   Author: ucfyao   File: market.py    (license) View Source Project 5 votes vote down vote up
def sell(self, amount, price, client_id=None):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, "CNY", self.currency)
        logging.verbose("Sell %f BTC at %f %s (%f CNY) @%s" % (amount,
                     local_currency_price, self.currency, price, self.name))
        if client_id:
            return self._sell(amount, local_currency_price, client_id)
        else:
            return self._sell(amount, local_currency_price) 
Example 8
Project: bitcoin-arbitrage   Author: ucfyao   File: market.py    (license) View Source Project 5 votes vote down vote up
def sell_maker(self, amount, price):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, "CNY", self.currency)
        local_currency_price = int(local_currency_price)

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

        return self._sell_maker(amount, local_currency_price) 
Example 9
Project: bitcoin-arbitrage   Author: ucfyao   File: arbitrer.py    (license) View Source Project 5 votes vote down vote up
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker())) 
Example 10
Project: Bitcoin-arbitrage---opportunity-detector   Author: yoshi717   File: arbitrage.py    (license) View Source Project 5 votes vote down vote up
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE") 
Example 11
Project: Bitcoin-arbitrage---opportunity-detector   Author: yoshi717   File: arbitrage.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 12
Project: Bitcoin-arbitrage---opportunity-detector   Author: yoshi717   File: arbitrage.py    (license) View Source Project 5 votes vote down vote up
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", type=str,
                            help="markets, example: -mMtGox,Bitstamp")
        parser.add_argument("command", nargs='*', default="watch",
                            help='verb: "watch|replay-history|get-balance|list-public-markets"')
        args = parser.parse_args()
        self.init_logger(args)
        self.exec_command(args) 
Example 13
Project: Bitcoin-arbitrage---opportunity-detector   Author: yoshi717   File: traderbot.py    (license) View Source Project 5 votes vote down vote up
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, kbid,
                            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, volume, kask, kbid,
                                      weighted_buyprice, weighted_sellprice,
                                      buyprice, sellprice]) 
Example 14
Project: Bitcoin-arbitrage---opportunity-detector   Author: yoshi717   File: arbitrer.py    (license) View Source Project 5 votes vote down vote up
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker())) 
Example 15
Project: salicapi   Author: Lafaiet   File: Log.py    (license) View Source Project 5 votes vote down vote up
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, msg, *args, **kwargs)
            logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, *args, **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.
    # 
Example 16
Project: salicapi   Author: Lafaiet   File: Log.py    (license) View Source Project 5 votes vote down vote up
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.
    # 
Example 17
Project: crypto-arbitrager   Author: artooze   File: arbitrage.py    (license) View Source Project 5 votes vote down vote up
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE") 
Example 18
Project: crypto-arbitrager   Author: artooze   File: market.py    (license) View Source Project 5 votes vote down vote up
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, price, self.name))
        if client_id:
            return self._buy(amount, local_currency_price, client_id)
        else:
            return self._buy(amount, local_currency_price) 
Example 19
Project: crypto-arbitrager   Author: artooze   File: market.py    (license) View Source Project 5 votes vote down vote up
def sell(self, amount, price, client_id=None):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, "CNY", self.currency)
        logging.verbose("Sell %f BTC at %f %s (%f CNY) @%s" % (amount,
                     local_currency_price, self.currency, price, self.name))
        if client_id:
            return self._sell(amount, local_currency_price, client_id)
        else:
            return self._sell(amount, local_currency_price) 
Example 20
Project: crypto-arbitrager   Author: artooze   File: market.py    (license) View Source Project 5 votes vote down vote up
def sell_maker(self, amount, price):
        """Orders are always priced in CNY"""
        local_currency_price = self.fc.convert(price, "CNY", self.currency)
        local_currency_price = int(local_currency_price)

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

        return self._sell_maker(amount, local_currency_price) 
Example 21
Project: crypto-arbitrager   Author: artooze   File: arbitrer.py    (license) View Source Project 5 votes vote down vote up
def tickers(self):
        for market in self.markets:
            logging.verbose("ticker: " + market.name + " - " + str(
                market.get_ticker())) 
Example 22
Project: kobo   Author: release-engineering   File: test_log.py    (license) View Source Project 5 votes vote down vote up
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") 
Example 23
Project: kobo   Author: release-engineering   File: log.py    (license) View Source Project 5 votes vote down vote up
def verbose(self, msg, *args, **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, msg, args), **kwargs) 
Example 24
Project: kobo   Author: release-engineering   File: log.py    (license) View Source Project 5 votes vote down vote up
def verbose(msg, *args, **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) 
Example 25
Project: bitcoin-arbitrage   Author: ucfyao   File: basicbot.py    (license) View Source Project 4 votes vote down vote up
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, kexchange, amount, price))
                return None
            
            if order_id == -1:
                logging.warn("%s @%s %f/%f BTC failed, %s" % (type, kexchange, amount, price, 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 
Example 26
Project: crypto-arbitrager   Author: artooze   File: basicbot.py    (license) View Source Project 4 votes vote down vote up
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.warn('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.warn('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, %s" % (type, kexchange, amount, price, order_id))
                return None
            
            if order_id == -1:
                logging.warn("%s @%s %f/%f BTC failed, %s" % (type, kexchange, amount, price, 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