本文整理汇总了Python中logging.log方法的典型用法代码示例。如果您正苦于以下问题:Python logging.log方法的具体用法?Python logging.log怎么用?Python logging.log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleHeader
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def handleHeader(self, key, value):
logging.log(self.getLogLevel(), "Got server header: %s:%s" % (key, value))
if (key.lower() == 'location'):
value = self.replaceSecureLinks(value)
if (key.lower() == 'content-type'):
if (value.find('image') != -1):
self.isImageRequest = True
logging.debug("Response is image content, not scanning...")
if (key.lower() == 'content-encoding'):
if (value.find('gzip') != -1):
logging.debug("Response is compressed...")
self.isCompressed = True
elif (key.lower() == 'content-length'):
self.contentLength = value
elif (key.lower() == 'set-cookie'):
self.client.responseHeaders.addRawHeader(key, value)
elif (key.lower()== 'strict-transport-security'):
logging.log(self.getLogLevel(), "LEO Erasing Strict Transport Security....")
else:
self.client.setHeader(key, value)
示例2: send_on_endpoint
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def send_on_endpoint(self, ep_num, data, blocking=True):
"""
Sends a collection of USB data on a given endpoint.
ep_num: The number of the IN endpoint on which data should be sent.
data: The data to be sent.
blocking: If true, this function will wait for the transfer to complete.
"""
logging.log(LOGLEVEL_TRACE, f"EP{ep_num}/IN: <- {bytes(data)}")
self._wait_until_ready_to_send(ep_num)
self.api.send_on_endpoint(ep_num, bytes(data))
# If we're blocking, wait until the transfer completes.
if blocking:
while not self._transfer_is_complete(ep_num, self.DEVICE_TO_HOST):
pass
self._clean_up_transfers_for_endpoint(ep_num, self.DEVICE_TO_HOST)
示例3: log_calls_with
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def log_calls_with(severity):
"""Create a decorator to log calls and return values of any function, for debugging."""
def decorator(fn):
@functools.wraps(fn)
def wrap(*params, **kwargs):
call_str = "%s(%s)" % (
fn.__name__, ", ".join([repr(p) for p in params] + ["%s=%s" % (k, repr(v)) for (k, v) in kwargs.items()]))
# TODO: Extract line number from caller and use that in logging.
log(severity, ">> %s", call_str)
ret = fn(*params, **kwargs)
# TODO: Add a way to make return short or omitted.
log(severity, "<< %s: %s", call_str, repr(ret))
return ret
return wrap
return decorator
# Convenience decorators for logging.
示例4: _set_config_value
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def _set_config_value(
self,
section_name,
option_name,
option_value,
logger=logging.getLogger(__name__),
_update_revision=True,
):
if not self.config:
raise ValueError("State configuration not yet loaded.")
if not self.config.has_section(section_name):
logger.log(logging.DEBUG, f"Adding config section {section_name}")
self.config.add_section(section_name)
self.config.set(section_name, option_name, option_value)
# update revision number
if _update_revision:
self._increase_revision_number()
self._write_state(logger=logger)
示例5: _step
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def _step(self):
step, _, loss, summary, targets, predictions, lengths = self._sess.run(self._fetches)
logging.log(HDEBUG, 'computing donwstream metrics')
metrics = dict((key, metric.reset().compute(targets, predictions, lengths))
for (key, metric) in self._metrics.items())
save_step = self._ckpt_every == 0 or (step % self._ckpt_every == 0)
ckpt = self._save_ckpt(step) if save_step else None
self._summarize(step, loss, summary, metrics, ckpt=ckpt)
if ckpt and self._eval:
self._eval.start(ckpt)
next_step = self._steps == 0 or step < self._steps
logging.log(HDEBUG, 'next step: %s', str(next_step))
return step, next_step
示例6: kill_ports
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def kill_ports(ports):
for port in ports:
log('kill %s start' % port)
popen = subprocess.Popen('lsof -i:%s' % port, shell = True, stdout = subprocess.PIPE)
(data, err) = popen.communicate()
log('data:\n%s \nerr:\n%s' % (data, err))
pattern = re.compile(r'\b\d+\b', re.S)
pids = re.findall(pattern, data)
log('pids:%s' % str(pids))
for pid in pids:
if pid != '' and pid != None:
try:
log('pid:%s' % pid)
popen = subprocess.Popen('kill -9 %s' % pid, shell = True, stdout = subprocess.PIPE)
(data, err) = popen.communicate()
log('data:\n%s \nerr:\n%s' % (data, err))
except Exception, e:
log('kill_ports exception:%s' % e)
log('kill %s finish' % port)
示例7: setup
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def setup(self, X, num_centers, alpha, save_to='dec_model'):
sep = X.shape[0]*9//10
X_train = X[:sep]
X_val = X[sep:]
ae_model = AutoEncoderModel(self.xpu, [X.shape[1],500,500,2000,10], pt_dropout=0.2)
if not os.path.exists(save_to+'_pt.arg'):
ae_model.layerwise_pretrain(X_train, 256, 50000, 'sgd', l_rate=0.1, decay=0.0,
lr_scheduler=mx.misc.FactorScheduler(20000,0.1))
ae_model.finetune(X_train, 256, 100000, 'sgd', l_rate=0.1, decay=0.0,
lr_scheduler=mx.misc.FactorScheduler(20000,0.1))
ae_model.save(save_to+'_pt.arg')
logging.log(logging.INFO, "Autoencoder Training error: %f"%ae_model.eval(X_train))
logging.log(logging.INFO, "Autoencoder Validation error: %f"%ae_model.eval(X_val))
else:
ae_model.load(save_to+'_pt.arg')
self.ae_model = ae_model
self.dec_op = DECModel.DECLoss(num_centers, alpha)
label = mx.sym.Variable('label')
self.feature = self.ae_model.encoder
self.loss = self.dec_op(data=self.ae_model.encoder, label=label, name='dec')
self.args.update({k:v for k,v in self.ae_model.args.items() if k in self.ae_model.encoder.list_arguments()})
self.args['dec_mu'] = mx.nd.empty((num_centers, self.ae_model.dims[-1]), ctx=self.xpu)
self.args_grad.update({k: mx.nd.empty(v.shape, ctx=self.xpu) for k,v in self.args.items()})
self.args_mult.update({k: k.endswith('bias') and 2.0 or 1.0 for k in self.args})
self.num_centers = num_centers
示例8: mnist_exp
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def mnist_exp(xpu):
X, Y = data.get_mnist()
dec_model = DECModel(xpu, X, 10, 1.0, 'data/mnist')
acc = []
for i in [10*(2**j) for j in range(9)]:
acc.append(dec_model.cluster(X, Y, i))
logging.log(logging.INFO, 'Clustering Acc: %f at update interval: %d'%(acc[-1], i))
logging.info(str(acc))
logging.info('Best Clustering ACC: %f at update_interval: %d'%(np.max(acc), 10*(2**np.argmax(acc))))
示例9: forward_end
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def forward_end(self, i, internals):
if i % self.interval == 0 and logging.getLogger().isEnabledFor(self.level):
for key in sorted(internals.keys()):
arr = internals[key]
logging.log(self.level, 'Iter:%d param:%s\t\tstat(%s):%s',
i, key, self.stat.__name__, str(self.stat(arr.asnumpy())))
示例10: backward_end
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def backward_end(self, i, weights, grads, metric=None):
if i % self.interval == 0 and logging.getLogger().isEnabledFor(self.level):
for key in sorted(grads.keys()):
arr = grads[key]
logging.log(self.level, 'Iter:%d param:%s\t\tstat(%s):%s\t\tgrad_stat:%s',
i, key, self.stat.__name__,
str(self.stat(weights[key].asnumpy())), str(self.stat(arr.asnumpy())))
if i % self.interval == 0 and metric is not None:
logging.log(logging.INFO, 'Iter:%d metric:%f', i, metric.get()[1])
metric.reset()
示例11: execute
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def execute(self):
logging.log("Executing Test Action!")
if 'msg' in self.params:
logging.log("Test Action Message: %s"%self.params['msg'])
示例12: log
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def log(level, message):
assert Logger.Initialized, 'Logger has not been initialized'
logging.log(level, message)
示例13: d
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def d(message):
Logger.log(logging.DEBUG, message)
示例14: i
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def i(message):
Logger.log(logging.INFO, message)
示例15: w
# 需要导入模块: import logging [as 别名]
# 或者: from logging import log [as 别名]
def w(message):
Logger.log(logging.WARNING, message)