本文整理汇总了Python中logging.basicConfig方法的典型用法代码示例。如果您正苦于以下问题:Python logging.basicConfig方法的具体用法?Python logging.basicConfig怎么用?Python logging.basicConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.basicConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def init_logging(log_file=None, append=False, console_loglevel=logging.INFO):
"""Set up logging to file and console."""
if log_file is not None:
if append:
filemode_val = 'a'
else:
filemode_val = 'w'
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
# datefmt='%m-%d %H:%M',
filename=log_file,
filemode=filemode_val)
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(console_loglevel)
# set a format which is simpler for console use
formatter = logging.Formatter("%(message)s")
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
global LOG
LOG = logging.getLogger(__name__)
示例2: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
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
示例3: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
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
示例4: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
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
示例5: main
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def main(argv):
logging.basicConfig(level=logging.INFO)
log_history = LogHistory(argv.config, argv.flow_dir, argv.port_dir, int(argv.num_steps), debug=True)
channel = "sdx_stats"
address = "192.168.99.100"
port = 6379
db = 0
publisher = Publisher(channel, address, port)
log_replay = LogReplay(log_history, publisher, int(argv.timestep), debug=True)
# start replay
replay_thread = Thread(target=log_replay.start)
replay_thread.daemon = True
replay_thread.start()
while replay_thread.is_alive():
try:
replay_thread.join(1)
except KeyboardInterrupt:
log_replay.stop()
示例6: lambda_handler
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def lambda_handler(event, context):
logger = logging.getLogger()
if logger.handlers:
for handler in logger.handlers:
logger.removeHandler(handler)
# change logging levels for boto and others
logging.getLogger("boto3").setLevel(logging.ERROR)
logging.getLogger("botocore").setLevel(logging.ERROR)
logging.getLogger("urllib3").setLevel(logging.ERROR)
# set logging format
logging.basicConfig(
format="[%(levelname)s] %(message)s (%(filename)s, %(funcName)s(), line %(lineno)d)",
level=os.environ.get("LOGLEVEL", "WARNING").upper(),
)
# instantiate class
retry = Retry(logging)
# run functions
retry.retry_security_events()
示例7: log_config
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def log_config(log_dir=None, log_file=None, prefix=None, rank=0):
reload(logging)
head = '%(asctime)-15s Node[' + str(rank) + '] %(message)s'
if log_dir:
logging.basicConfig(level=logging.DEBUG, format=head)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
if not log_file:
log_file = (prefix if prefix else '') + datetime.now().strftime('_%Y_%m_%d-%H_%M.log')
log_file = log_file.replace('/', '-')
else:
log_file = log_file
log_file_full_name = os.path.join(log_dir, log_file)
handler = logging.FileHandler(log_file_full_name, mode='w')
formatter = logging.Formatter(head)
handler.setFormatter(formatter)
logging.getLogger().addHandler(handler)
logging.info('start with arguments %s', args)
else:
logging.basicConfig(level=logging.DEBUG, format=head)
logging.info('start with arguments %s', args)
示例8: _controller
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def _controller(self):
"""Return the server controller."""
def server_controller(cmd_id, cmd_body, _):
"""Server controler."""
if not self.init_logginig:
# the reason put the codes here is because we cannot get
# kvstore.rank earlier
head = '%(asctime)-15s Server[' + str(
self.kvstore.rank) + '] %(message)s'
logging.basicConfig(level=logging.DEBUG, format=head)
self.init_logginig = True
if cmd_id == 0:
try:
optimizer = pickle.loads(cmd_body)
except:
raise
self.kvstore.set_optimizer(optimizer)
else:
print("server %d, unknown command (%d, %s)" % (
self.kvstore.rank, cmd_id, cmd_body))
return server_controller
示例9: test_lenet
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def test_lenet(devs, kv_type):
logging.basicConfig(level=logging.DEBUG)
(train, val) = mnist(batch_size = batch_size, input_shape=(1,28,28))
# guarantee the same weight init for each run
mx.random.seed(0)
model = mx.model.FeedForward(
ctx = devs,
symbol = net,
num_epoch = 2,
learning_rate = 0.1,
momentum = 0.9,
wd = 0.00001)
model.fit(
kvstore = kv_type,
X = train)
return accuracy(model, val)
示例10: test_profile_task
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def test_profile_task():
def makeParams():
objects = tuple('foo' for _ in range(50))
template = ''.join('{%d}' % i for i in range(len(objects)))
return template, objects
def doLog():
template, objects = makeParams()
for _ in range(100000):
logging.info(template.format(*objects))
logging.basicConfig()
enable_profiler('test_profile_task.json')
python_domain = profiler.Domain('PythonDomain::test_profile_task')
task = profiler.Task(python_domain, "test_profile_task")
task.start()
start = time.time()
var = mx.nd.ones((1000, 500))
doLog()
var.asnumpy()
stop = time.time()
task.stop()
print('run took: %.3f' % (stop - start))
profiler.set_state('stop')
示例11: test_profile_frame
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def test_profile_frame():
def makeParams():
objects = tuple('foo' for _ in range(50))
template = ''.join('{%d}' % i for i in range(len(objects)))
return template, objects
def doLog():
template, objects = makeParams()
for _ in range(100000):
logging.info(template.format(*objects))
logging.basicConfig()
enable_profiler('test_profile_frame.json')
python_domain = profiler.Domain('PythonDomain::test_profile_frame')
frame = profiler.Frame(python_domain, "test_profile_frame")
frame.start()
start = time.time()
var = mx.nd.ones((1000, 500))
doLog()
var.asnumpy()
stop = time.time()
frame.stop()
print('run took: %.3f' % (stop - start))
profiler.set_state('stop')
示例12: exec_mnist
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def exec_mnist(model, train_dataiter, val_dataiter):
# print logging by default
logging.basicConfig(level=logging.DEBUG)
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
logging.getLogger('').addHandler(console)
model.fit(X=train_dataiter,
eval_data=val_dataiter)
logging.info('Finish fit...')
prob = model.predict(val_dataiter)
logging.info('Finish predict...')
val_dataiter.reset()
y = np.concatenate([batch.label[0].asnumpy() for batch in val_dataiter]).astype('int')
py = np.argmax(prob, axis=1)
acc1 = float(np.sum(py == y)) / len(y)
logging.info('final accuracy = %f', acc1)
assert(acc1 > 0.94)
# run as a script
示例13: test_cifar10
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def test_cifar10():
# print logging by default
logging.basicConfig(level=logging.DEBUG)
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
logging.getLogger('').addHandler(console)
kv = mx.kvstore.create("local")
# test float32 input
(train, val) = get_iterator_float32(kv)
run_cifar10(train, val, use_module=False)
run_cifar10(train, val, use_module=True)
# test legecay tuple in provide_data and provide_label
run_cifar10(CustomDataIter(train), CustomDataIter(val), use_module=False)
run_cifar10(CustomDataIter(train), CustomDataIter(val), use_module=True)
# test uint8 input
(train, val) = get_iterator_uint8(kv)
run_cifar10(train, val, use_module=False)
run_cifar10(train, val, use_module=True)
示例14: main
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def main():
'''Entry-point function for the cookiejar Transaction Processor.'''
try:
# Setup logging for this class.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
# Register the Transaction Handler and start it.
processor = TransactionProcessor(url=DEFAULT_URL)
sw_namespace = _hash(FAMILY_NAME.encode('utf-8'))[0:6]
handler = CookieJarTransactionHandler(sw_namespace)
processor.add_handler(handler)
processor.start()
except KeyboardInterrupt:
pass
except SystemExit as err:
raise err
except BaseException as err:
traceback.print_exc(file=sys.stderr)
sys.exit(1)
示例15: create
# 需要导入模块: import logging [as 别名]
# 或者: from logging import basicConfig [as 别名]
def create(gearkey,gearsecret, appid="", args = {}):
if 'debugmode' in args:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p',
)
else:
logging.basicConfig(level=logging.WARNING,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p',
)
microgear.gearalias = args.get('alias',"")[0:16]
if 'scope' in args:
matchScope = re.match( r'^(\w+:[a-zA-Z\/]+,*)+$', args['scope'])
if matchScope:
microgear.scope = args["scope"]
else:
microgear.scope = ""
logging.warning("Specify scope is not valid")
microgear.gearkey = gearkey
microgear.gearsecret = gearsecret
microgear.appid = appid