Commit cf8c0aa9 by Calen Pennington

Extract a baseclass for Formatters

parent f0ae1358
...@@ -34,10 +34,15 @@ class Timestamp(object): ...@@ -34,10 +34,15 @@ class Timestamp(object):
return self.end - self.start return self.end - self.start
class DatadogFormatter(object): class Formatter(object):
def __init__(self, callback_module): def __init__(self, callback_module):
self.callback_module = callback_module self.callback_module = callback_module
class DatadogFormatter(Formatter):
def __init__(self, callback_module):
super(DatadogFormatter, self).__init__(callback_module)
self.datadog_api_key = os.getenv('DATADOG_API_KEY') self.datadog_api_key = os.getenv('DATADOG_API_KEY')
self.datadog_api_initialized = False self.datadog_api_initialized = False
...@@ -82,10 +87,7 @@ class DatadogFormatter(object): ...@@ -82,10 +87,7 @@ class DatadogFormatter(object):
logger.error(ex.message) logger.error(ex.message)
class JsonFormatter(object): class JsonFormatter(Formatter):
def __init__(self, callback_module):
self.callback_module = callback_module
def log_tasks(self, playbook_name, results): def log_tasks(self, playbook_name, results):
if ANSIBLE_TIMER_LOG is not None: if ANSIBLE_TIMER_LOG is not None:
log_path = self.callback_module.playbook_timestamp.start.strftime(ANSIBLE_TIMER_LOG) log_path = self.callback_module.playbook_timestamp.start.strftime(ANSIBLE_TIMER_LOG)
...@@ -138,10 +140,7 @@ class JsonFormatter(object): ...@@ -138,10 +140,7 @@ class JsonFormatter(object):
outfile.write('\n') outfile.write('\n')
class LoggingFormatter(object): class LoggingFormatter(Formatter):
def __init__(self, callback_module):
self.callback_module = callback_module
def log_tasks(self, playbook_name, results): def log_tasks(self, playbook_name, results):
for name, timestamp in results[:10]: for name, timestamp in results[:10]:
logger.info( logger.info(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment