示例#1
0
    :return: json of the stats | Log not found message
    """
    res = LogParser.get_stats(LOG_FILE)
    if not isinstance(res, Result):
        logging.warning(
            "File with path {} could not be parse!".format(LOG_FILE))
        return make_response(
            jsonify(message="Log file for path {} could not be parse!".format(
                LOG_FILE)), 400)
    return make_response(res.get_as_json(), 200)


with app.app_context():
    """
    After startup the logger will be initiated to parse the configured log file and cache the results.
    During this initial operation, the app can not yet process any requests.
    """
    logging.info(
        "Initial parsing of log file with path {}, please wait...".format(
            LOG_FILE))
    try:
        LogParser.init(LOG_FILE)
    except ValueError as err:
        logging.error("Could not parse configured file!")
    logging.info("Done parsing! Ready to serve stats...")

if __name__ == "__main__":
    """Run flask app"""
    app.run(port=LISTEN_PORT)
    logging.info("Service running on port {}!".format(LISTEN_PORT))