本文整理匯總了Python中modules.util.log.LogFactory類的典型用法代碼示例。如果您正苦於以下問題:Python LogFactory類的具體用法?Python LogFactory怎麽用?Python LogFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了LogFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
# php_start_command = "/usr/sbin/apache2ctl -D FOREGROUND"
php_start_command = "/etc/init.d/apache2 restart"
p = subprocess.Popen(php_start_command, shell=True)
output, errors = p.communicate()
log.debug("Apache server started: [command] %s, [output] %s" % (php_start_command, output))
示例2: DefaultHealthStatisticsReader
class DefaultHealthStatisticsReader(IHealthStatReaderPlugin):
"""
Default implementation for the health statistics reader
"""
def __init__(self):
super(DefaultHealthStatisticsReader, self).__init__()
self.log = LogFactory().get_log(__name__)
def stat_cartridge_health(self, ca_health_stat):
ca_health_stat.memory_usage = DefaultHealthStatisticsReader.__read_mem_usage()
ca_health_stat.load_avg = DefaultHealthStatisticsReader.__read_load_avg()
self.log.debug("Memory read: %r, CPU read: %r" % (ca_health_stat.memory_usage, ca_health_stat.load_avg))
return ca_health_stat
@staticmethod
def __read_mem_usage():
return psutil.virtual_memory().percent
@staticmethod
def __read_load_avg():
(one, five, fifteen) = os.getloadavg()
cores = multiprocessing.cpu_count()
return (one / cores) * 100
示例3: MessageBrokerHeartBeatChecker
class MessageBrokerHeartBeatChecker(AbstractAsyncScheduledTask):
"""
A scheduled task to periodically check if the connected message broker is online.
If the message broker goes offline, it will disconnect the currently connected
client object and it will return from the loop_forever() method.
"""
def __init__(self, connected_client, mb_ip, mb_port, username=None, password=None):
self.__mb_client = mqtt.Client()
if username is not None:
self.__mb_client.username_pw_set(username, password)
self.__mb_ip = mb_ip
self.__mb_port = mb_port
self.__connected_client = connected_client
self.__log = LogFactory().get_log(__name__)
def execute_task(self):
try:
self.__mb_client.connect(self.__mb_ip, self.__mb_port, 60)
self.__mb_client.disconnect()
except Exception:
self.__log.info(
"Message broker %s:%s cannot be reached. Disconnecting client..." % (self.__mb_ip, self.__mb_port))
self.__connected_client.disconnect()
示例4: export_env_var
def export_env_var(self, variable, value):
log = LogFactory().get_log(__name__)
if value is not None:
os.environ[variable] = value
log.info("Exported environment variable %s: %s" % (variable, value))
else:
log.warn("Could not export environment variable %s " % variable)
示例5: EventSubscriber
class EventSubscriber(threading.Thread):
"""
Provides functionality to subscribe to a given topic on the Stratos MB and
register event handlers for various events.
"""
def __init__(self, topic, ip, port):
threading.Thread.__init__(self)
self.__event_queue = Queue(maxsize=0)
self.__event_executor = EventExecutor(self.__event_queue)
self.log = LogFactory().get_log(__name__)
self.__mb_client = None
self.__topic = topic
self.__subscribed = False
self.__ip = ip
self.__port = port
def run(self):
# Start the event executor thread
self.__event_executor.start()
self.__mb_client = mqtt.Client()
self.__mb_client.on_connect = self.on_connect
self.__mb_client.on_message = self.on_message
self.log.debug("Connecting to the message broker with address %r:%r" % (self.__ip, self.__port))
self.__mb_client.connect(self.__ip, self.__port, 60)
self.__subscribed = True
self.__mb_client.loop_forever()
def register_handler(self, event, handler):
"""
Adds an event handler function mapped to the provided event.
:param str event: Name of the event to attach the provided handler
:param handler: The handler function
:return: void
:rtype: void
"""
self.__event_executor.register_event_handler(event, handler)
self.log.debug("Registered handler for event %r" % event)
def on_connect(self, client, userdata, flags, rc):
self.log.debug("Connected to message broker.")
self.__mb_client.subscribe(self.__topic)
self.log.debug("Subscribed to %r" % self.__topic)
def on_message(self, client, userdata, msg):
self.log.debug("Message received: %s:\n%s" % (msg.topic, msg.payload))
self.__event_queue.put(msg)
def is_subscribed(self):
"""
Checks if this event subscriber is successfully subscribed to the provided topic
:return: True if subscribed, False if otherwise
:rtype: bool
"""
return self.__subscribed
示例6: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
# start tomcat
tomcat_start_command = "exec ${CATALINA_HOME}/bin/startup.sh"
log.info("Starting Tomcat server: [command] %s" % tomcat_start_command)
p = subprocess.Popen(tomcat_start_command, shell=True)
output, errors = p.communicate()
log.debug("Tomcat server started: [command] %s, [output] %s" % (p.args, output))
示例7: checkout
def checkout(self, repo_info):
log = LogFactory().get_log(__name__)
try:
log.info("Running extension for checkout job")
repo_info = values['REPO_INFO']
git_repo = AgentGitHandler.create_git_repo(repo_info)
AgentGitHandler.add_repo(git_repo)
except Exception as e:
log.exception("Error while executing CheckoutJobHandler extension: %s" % e)
示例8: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
# wait till SAML_ENDPOINT becomes available
mds_response = None
while mds_response is None:
log.debug("Waiting for SAML_ENDPOINT to be available from metadata service for app ID: %s" % values["APPLICATION_ID"])
time.sleep(5)
mds_response = mdsclient.get(app=True)
if mds_response is not None and mds_response.properties.get("SAML_ENDPOINT") is None:
mds_response = None
saml_endpoint = mds_response.properties["SAML_ENDPOINT"]
log.debug("SAML_ENDPOINT value read from Metadata service: %s" % saml_endpoint)
# start tomcat
tomcat_start_command = "exec /opt/tomcat/bin/startup.sh"
log.info("Starting Tomcat server: [command] %s, [STRATOS_SAML_ENDPOINT] %s" % (tomcat_start_command, saml_endpoint))
env_var = os.environ.copy()
env_var["STRATOS_SAML_ENDPOINT"] = saml_endpoint
env_var["STRATOS_HOST_NAME"] = values["HOST_NAME"]
payload_ports = values["PORT_MAPPINGS"].split("|")
if values.get("LB_CLUSTER_ID") is not None:
port_no = payload_ports[2].split(":")[1]
else:
port_no = payload_ports[1].split(":")[1]
env_var["STRATOS_HOST_PORT"] = port_no
p = subprocess.Popen(tomcat_start_command, env=env_var, shell=True)
output, errors = p.communicate()
log.debug("Tomcat server started")
示例9: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
# start server
log.info("Starting APACHE STORM SUPERVISOR...")
start_command = "${CARBON_HOME}/bin/storm supervisor"
env_var = os.environ.copy()
p = subprocess.Popen(start_command, env=env_var, shell=True)
output, errors = p.communicate()
log.debug("APACHE STORM SUPERVISOR started successfully")
示例10: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
os.environ["GIT_SSL_NO_VERIFY"] = "1"
s2gitDomain = values.get("S2GIT_DOMAIN")
s2gitIP = values.get("S2GIT_IP")
entry_command = "echo '"+ s2gitIP + " "+ s2gitDomain + "' >> /etc/hosts"
env_var = os.environ.copy()
p = subprocess.Popen(entry_command, env=env_var, shell=True)
output, errors = p.communicate()
log.info("S2git host entry added successfully")
示例11: run_plugin
def run_plugin(self, values):
self.log = LogFactory().get_log(__name__)
self.log.info("Starting Clustering Configuration")
clusterId = values['CLUSTER_ID']
self.log.info("CLUSTER_ID %s" % clusterId)
service_name = values['SERVICE_NAME']
self.log.info("SERVICE_NAME %s" % service_name)
cluering_type = values['CLUSTERING_TYPE']
self.log.info("CLUSTERING_TYPE %s" % cluering_type)
is_wka_member = values['WKA_MEMBER']
self.log.info("WKA_MEMBER %s" % is_wka_member)
self.my_member_id = values['MEMBER_ID']
self.log.info("MEMBER_ID %s" % self.my_member_id)
sub_domain = values['SUB_DOMAIN']
sub_domain= "'{}'".format(sub_domain)
self.log.info("SUB_DOMAIN %s" % (sub_domain))
os.environ['STRATOS_SUB_DOMAIN'] = str(sub_domain)
self.log.info("env clustering SUB_DOMAIN=%s" % (os.environ.get('SUB_DOMAIN','worker')))
if WkaMemberConfigurator.isTrue(is_wka_member):
self.log.info("This is a WKA member")
self.remove_me_from_queue()
self.publish_wka_members(service_name, clusterId)
else:
self.log.info("This is not a WKA member")
self.fetch_wka_members()
self.execute_clustring_configurater()
示例12: run_plugin
def run_plugin(self, values):
self.log = LogFactory().get_log(__name__)
self.log.info("Starting Clustering Configuration")
clusterId = values['CLUSTER_ID']
self.log.info("CLUSTER_ID %s" % clusterId)
service_name = values['SERVICE_NAME']
self.log.info("SERVICE_NAME %s" % service_name)
cluering_type = values['CLUSTERING_TYPE']
self.log.info("CLUSTERING_TYPE %s" % cluering_type)
is_wka_member = values['WKA_MEMBER']
self.log.info("WKA_MEMBER %s" % is_wka_member)
self.my_member_id = values['MEMBER_ID']
self.log.info("MEMBER_ID %s" % self.my_member_id)
if self.is_wka(WkaMemberConfigurator.isTrue(is_wka_member)):
self.log.info("This is a WKA member")
self.remove_me_from_queue()
self.get_all_members(service_name, clusterId)
else:
self.log.info("This is not a WKA member")
self.fetch_wka_members()
示例13: execute_script
def execute_script(bash_file, extension_values):
""" Execute the given bash files in the <PCA_HOME>/extensions/bash folder
:param bash_file: name of the bash file to execute
:return: tuple of (output, errors)
"""
log = LogFactory().get_log(__name__)
working_dir = os.path.abspath(os.path.dirname(__file__))
command = working_dir[:-2] + "bash/" + bash_file
current_env_vars = os.environ.copy()
extension_values.update(current_env_vars)
log.debug("Execute bash script :: %s" % command)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=extension_values)
output, errors = p.communicate()
return output, errors
示例14: run_plugin
def run_plugin(self, values):
log = LogFactory().get_log(__name__)
event_name = values["EVENT"]
log.debug("Running extension for %s" % event_name)
extension_values = {}
for key in values.keys():
extension_values["STRATOS_" + key] = values[key]
# log.debug("%s => %s" % ("STRATOS_" + key, extension_values["STRATOS_" + key]))
try:
output, errors = ExtensionExecutor.execute_script(event_name + ".sh")
except OSError:
raise RuntimeError("Could not find an extension file for event %s" % event_name)
if len(errors) > 0:
raise RuntimeError("Extension execution failed for script %s: %s" % (event_name, errors))
log.info("%s Extension executed. [output]: %s" % (event_name, output))
示例15: __init__
def __init__(self, connected_client, mb_ip, mb_port, username=None, password=None):
self.__mb_client = mqtt.Client()
if username is not None:
self.__mb_client.username_pw_set(username, password)
self.__mb_ip = mb_ip
self.__mb_port = mb_port
self.__connected_client = connected_client
self.__log = LogFactory().get_log(__name__)