当前位置: 首页>>代码示例>>Python>>正文


Python logger.Logger方法代码示例

本文整理汇总了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 
开发者ID:xbpeng,项目名称:awr,代码行数:7,代码来源:rl_agent.py

示例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 
开发者ID:xbpeng,项目名称:awr,代码行数:9,代码来源:rl_agent.py

示例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 
开发者ID:xbpeng,项目名称:awr,代码行数:7,代码来源:rl_agent.py

示例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 
开发者ID:xbpeng,项目名称:awr,代码行数:16,代码来源:rl_agent.py

示例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() 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:35,代码来源:main.py

示例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) 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:17,代码来源:schedule_resource_handler.py

示例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 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:40,代码来源:scheduler_request_handler.py

示例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"] 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:16,代码来源:scheduler_setup_handler.py

示例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) 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:14,代码来源:cloudwatch_event_handler.py

示例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 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:36,代码来源:admin_api_request_handler.py

示例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) 
开发者ID:awslabs,项目名称:aws-instance-scheduler,代码行数:43,代码来源:admin_cli_request_handler.py

示例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 
开发者ID:xbpeng,项目名称:awr,代码行数:60,代码来源:rl_agent.py


注:本文中的util.logger.Logger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。