本文整理匯總了Python中util.logger.Logger方法的典型用法代碼示例。如果您正苦於以下問題:Python logger.Logger方法的具體用法?Python logger.Logger怎麽用?Python logger.Logger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類util.logger
的用法示例。
在下文中一共展示了logger.Logger方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: eval
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def eval(self, num_episodes):
test_return, test_path_count = self._rollout_test(num_episodes, print_info=True)
logger.Logger.print("Test_Return: {:.3f}".format(test_return))
logger.Logger.print("Test_Paths: {:.3f}".format(test_path_count))
return
示例2: save_model
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def save_model(self, out_path):
try:
save_path = self._saver.save(self._sess, out_path, write_meta_graph=False, write_state=False)
logger.Logger.print("Model saved to: " + save_path)
except:
logger.Logger.print("Failed to save model to: " + out_path)
return
示例3: load_model
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def load_model(self, in_path):
self._saver.restore(self._sess, in_path)
self._load_normalizers()
logger.Logger.print("Model loaded from: " + in_path)
return
示例4: _rollout_test
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def _rollout_test(self, num_episodes, print_info=False):
total_return = 0
for e in range(num_episodes):
path = self._rollout_path(test=True)
path_return = path.calc_return()
total_return += path_return
if (print_info):
logger.Logger.print("Episode: {:d}".format(e))
logger.Logger.print("Curr_Return: {:.3f}".format(path_return))
logger.Logger.print("Avg_Return: {:.3f}\n".format(total_return / (e + 1)))
avg_return = total_return / num_episodes
return avg_return, num_episodes
示例5: lambda_handler
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def lambda_handler(event, context):
try:
dt = datetime.utcnow()
log_stream = LOG_STREAM.format(dt.year, dt.month, dt.day)
result = {}
with Logger(logstream=log_stream, buffersize=20, context=context,
debug=util.as_bool(os.getenv(configuration.ENV_TRACE, False))) as logger:
logger.info("InstanceScheduler, version {}".format(VERSION))
logger.debug("Event is {}", util.safe_json(event, indent=3))
for handler_type in [SchedulerRequestHandler,
SchedulerSetupHandler,
ScheduleResourceHandler,
AdminCliRequestHandler,
CloudWatchEventHandler]:
if handler_type.is_handling_request(event):
start = time()
handler = handler_type(event, context)
logger.info("Handler is {}".format(handler_type.__name__))
try:
result = handler.handle_request()
except Exception as e:
logger.error("Error handling request {} by handler {}: ({})\n{}", json.dumps(event), handler_type.__name__,
e, traceback.format_exc())
execution_time = round(float((time() - start)), 3)
logger.info("Handling took {} seconds", execution_time)
return result
logger.debug("Request was not handled, no handler was able to handle this type of request {}", json.dumps(event))
finally:
configuration.unload_scheduler_configuration()
示例6: __init__
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def __init__(self, event, context):
"""
Initializes instance
:param event: CFN event
:param context: Lambda context
"""
CustomResource.__init__(self, event, context)
self.number_of_periods = 0
classname = self.__class__.__name__
dt = datetime.utcnow()
logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=logstream, buffersize=20, context=context)
self._admin = ConfigAdmin(logger=self._logger, context=context)
示例7: handle_request
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def handle_request(self):
"""
Handles the event
:return:
"""
result = {}
account_names = list(self.account_names)
for service in self.configuration.scheduled_services:
# gets the implementation that handles the actual scheduling for the service
service_strategy = SCHEDULER_TYPES[service]()
# create a scheduler and pass the service strategy
scheduler = InstanceScheduler(service=service_strategy, scheduler_configuration=self.configuration)
# setup logging for the service/account/region
s = "-".join([LOG_STREAM_PREFIX, service, "-".join(account_names), "-".join(self.configuration.regions)])
dt = datetime.utcnow()
logstream = LOG_STREAM.format(s, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=logstream, buffersize=60 if self.configuration.trace else 30, context=self._context,
debug=self.configuration.trace)
try:
self._logger.info(INF_HANDLER.format(
self.__class__.__name__,
", ".join(self.configuration.scheduled_services),
", ".join(list(self.account_names)),
", ".join(list(self.configuration.regions)),
datetime.now()))
# run the scheduler for the service
result[service] = scheduler.run(state_table=self.state_table, scheduler_config=self.configuration,
lambda_account=self.lambda_account, context=self._context, logger=self._logger)
self._logger.info(INF_SCHEDULER_RESULT, result[service])
finally:
self._logger.flush()
return result
示例8: __init__
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def __init__(self, event, context):
CustomResource.__init__(self, event, context)
# Setup logging
classname = self.__class__.__name__
dt = datetime.utcnow()
log_stream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=log_stream, buffersize=1, context=context)
self.arguments = copy(self.resource_properties)
self.arguments = {a: self.resource_properties[a] for a in self.resource_properties if a not in ["ServiceToken",
"Timeout"]}
self._stack_version = self.arguments["stack_version"]
示例9: __init__
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def __init__(self, event, context):
self._context = context
self._event = event
self._configuration = None
self._lambda_client = None
# Setup logging
classname = self.__class__.__name__
dt = datetime.utcnow()
logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=logstream, buffersize=30, context=context)
示例10: handle_request
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def handle_request(self):
"""
Handles the event
:return: result of handling the event, result send back to REST admin api
"""
# Setup logging
classname = self.__class__.__name__
dt = datetime.utcnow()
logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=logstream, buffersize=20, context=self._context)
with Logger(logstream=logstream, buffersize=20, context=self._context) as logger:
logger.info("Handler {} : Received request {}", self.__class__.__name__, json.dumps(self._event))
# get access to admin api
admin = ConfigAdmin(logger=logger, context=self._context)
# get api action and map it to a function in the admin API
fn = getattr(admin, self.action)
if fn is None:
raise ValueError("Action {} does not exist".format(self.action))
# build parameters for admin API call
temp = self._event.get("params", {})
params = {p: temp[p] for p in temp}
if "name" in self._event:
params["name"] = self._event["name"]
logger.info("Calling \"{}\" with parameters {}", fn.__name__, params)
# call the admin API
result = fn(**params)
logger.info("Call result is {}", result)
return result
示例11: __init__
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def __init__(self, event, context):
"""
Initializes handle instance
:param event: event to handle
:param context: lambda context
"""
self._event = event
self._context = context
self._logger = None
self.additional_parameters = {
"delete-period": {"exception_if_not_exists": True},
"delete-schedule": {"exception_if_not_exists": True}
}
self.transform_parameters = {
"metrics": "use-metrics"
}
self.commands = {
"create-period": "create_period",
"create-schedule": "create_schedule",
"delete-period": "delete_period",
"delete-schedule": "delete_schedule",
"describe-periods": "list_periods" if self.parameters.get(configuration.NAME) is None else "get_period",
"describe-schedule-usage": "get_schedule_usage",
"describe-schedules": "list_schedules" if self.parameters.get(configuration.NAME) is None else "get_schedule",
"update-period": "update_period",
"update-schedule": "update_schedule"
}
self.transformations = {
"get_period": "{Periods:[Period]}",
"get_schedule": "{Schedules:[Schedule]}"
}
# Setup logging
classname = self.__class__.__name__
dt = datetime.utcnow()
log_stream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
self._logger = Logger(logstream=log_stream, buffersize=20, context=self._context)
示例12: train
# 需要導入模塊: from util import logger [as 別名]
# 或者: from util.logger import Logger [as 別名]
def train(self, max_iter, test_episodes, output_dir, output_iters):
log_file = os.path.join(output_dir, "log.txt")
self._logger = logger.Logger()
self._logger.configure_output_file(log_file)
model_file = os.path.join(output_dir, "model.ckpt")
iter = 0
total_train_return = 0
total_train_path_count = 0
test_return = 0
test_path_count = 0
start_time = time.time()
while (iter < max_iter):
train_return, train_path_count, new_sample_count = self._rollout_train(self._samples_per_iter)
total_train_return += train_path_count * train_return
total_train_path_count += train_path_count
avg_train_return = total_train_return / total_train_path_count
total_samples = self.get_total_samples()
wall_time = time.time() - start_time
wall_time /= 60 * 60 # store time in hours
self._logger.log_tabular("Iteration", iter)
self._logger.log_tabular("Wall_Time", wall_time)
self._logger.log_tabular("Samples", total_samples)
self._logger.log_tabular("Train_Return", avg_train_return)
self._logger.log_tabular("Train_Paths", total_train_path_count)
self._logger.log_tabular("Test_Return", test_return)
self._logger.log_tabular("Test_Paths", test_path_count)
if (self._need_normalizer_update() and iter == 0):
self._update_normalizers()
self._update(iter, new_sample_count)
if (self._need_normalizer_update()):
self._update_normalizers()
if (iter % output_iters == 0):
test_return, test_path_count = self._rollout_test(test_episodes, print_info=False)
self._logger.log_tabular("Test_Return", test_return)
self._logger.log_tabular("Test_Paths", test_path_count)
self.save_model(model_file)
self._logger.print_tabular()
self._logger.dump_tabular()
total_train_return = 0
total_train_path_count = 0
else:
self._logger.print_tabular()
iter += 1
return