def get_default_handler(self): """Return the default logging handler based on the local environment. :rtype: :class:`logging.Handler` :returns: The default log handler based on the environment """ if (_APPENGINE_FLEXIBLE_ENV_VM in os.environ or _APPENGINE_FLEXIBLE_ENV_FLEX in os.environ): return AppEngineHandler() elif _CONTAINER_ENGINE_ENV in os.environ: return ContainerEngineHandler() else: return CloudLoggingHandler(self)
def get_default_handler(self): """Return the default logging handler based on the local environment. :rtype: :class:`logging.Handler` :returns: The default log handler based on the environment """ gke_cluster_name = retrieve_metadata_server(_GKE_CLUSTER_NAME) if (_APPENGINE_FLEXIBLE_ENV_VM in os.environ or _APPENGINE_FLEXIBLE_ENV_FLEX in os.environ): return AppEngineHandler(self) elif gke_cluster_name is not None: return ContainerEngineHandler() else: return CloudLoggingHandler(self)
def get_default_handler(self, **kw): """Return the default logging handler based on the local environment. :type kw: dict :param kw: keyword args passed to handler constructor :rtype: :class:`logging.Handler` :returns: The default log handler based on the environment """ gke_cluster_name = retrieve_metadata_server(_GKE_CLUSTER_NAME) if (_APPENGINE_FLEXIBLE_ENV_VM in os.environ or _APPENGINE_INSTANCE_ID in os.environ): return AppEngineHandler(self, **kw) elif gke_cluster_name is not None: return ContainerEngineHandler(**kw) else: return CloudLoggingHandler(self, **kw)
from datetime import datetime, timedelta from google.cloud.logging.handlers import ContainerEngineHandler from ib_insync import IB, Future import logging from math import isnan from os import environ from random import randint # setup logging module_logger = logging.getLogger('strategy-api.es-random') module_logger.setLevel(logging.DEBUG) module_logger.addHandler(ContainerEngineHandler()) # get environment variables GATEWAY = environ.get('GATEWAY', default='ib-gw-paper') # define specs of contracts used CONTRACT_SPECS = { 'ES': { 'months': ['H', 'M', 'U', 'Z'], 'exchange': 'GLOBEX', 'currency': 'USD' } } # instantiate ib-insync IB gateway ib_gw = IB() def get_contracts(series, n): """ Requests contract details for a series of futures
import sys from flask import Flask from flask import jsonify from flask import request import jwt from functools import wraps from flasgger import Swagger from flasgger import swag_from from google.cloud.logging.handlers import ContainerEngineHandler import logging from lib import prediction, secrets formatter = logging.Formatter("%(message)s") handler = ContainerEngineHandler(stream=sys.stderr) handler.setFormatter(formatter) handler.setLevel(logging.INFO) root = logging.getLogger() root.addHandler(handler) root.setLevel(logging.INFO) app = Flask(__name__) app.config["JSON_SORT_KEYS"] = False app.config["SWAGGER"] = { "specs": [{ "endpoint": "apispec_1", "route": "/api/apispec_1.json", "rule_filter": lambda rule: True, # all in "model_filter": lambda tag: True, # all in }], "static_url_path": "/api/flasgger_static",
import falcon from google.cloud.logging.handlers import ContainerEngineHandler from importlib import import_module import json import logging from os import environ # setup logging main_logger = logging.getLogger('strategy-api.main') main_logger.setLevel(logging.DEBUG) main_logger.addHandler(ContainerEngineHandler()) # get environment variables STRATEGY = environ.get('STRATEGY') # import strategy module strategy_module = import_module('strategies.' + STRATEGY) if STRATEGY is not None else None class HealthCheck: def __init__(self): main_logger.info('Strategy API healthcheck is active.') @staticmethod def on_get(_, response): main_logger.info('Strategy API healthcheck succeded.') response.status = falcon.HTTP_200 response.body = '{"status": "ok"}'