Skip to content

Commit

Permalink
Merge pull request #3 from StealthyLoner/fix_logging
Browse files Browse the repository at this point in the history
Fix logging
  • Loading branch information
jjonek committed Aug 26, 2015
2 parents 4e4d0de + add07af commit 7914234
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions slamon_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, afm_url, default_wait=60, max_tasks=2, name='Python Agent 1.0
self.name = name
self.uuid = agent_uuid if agent_uuid else str(uuid.uuid1())
self._run = True
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message).120s")

def exit(self):
"""
Expand Down Expand Up @@ -81,8 +82,6 @@ def _import_module(module_name, package=None):

def main():
"""Entry point for the agent script."""
logging.basicConfig(level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url', action='store', required=True,
help='Coordinator URL')
Expand All @@ -92,13 +91,17 @@ def main():
help='Seconds to wait before reconnection after connection failure.')
parser.add_argument('-x', '--num-executors', type=int, default=2,
help='Number of concurrent task executors.')
parser.add_argument('--verbose', '-v', action='count', default=0,
help='Increase logging verbosity. Default logging level is WARNING.')
args = parser.parse_args()

# import defined modules to load defined handlers
if args.load:
for module in args.load:
_import_module(module)

logging.basicConfig(level=max(logging.WARNING - (args.verbose * 10), 0))

agent = Agent(
args.url,
default_wait=args.default_wait,
Expand Down
4 changes: 2 additions & 2 deletions slamon_agent/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def request_tasks(self, **kwargs):
}
request_data.update(kwargs)

logging.getLogger('HTTP').debug("Requesting for tasks: %s", request_data)
logging.getLogger('HTTP').info("Requesting for tasks: %s", request_data)
r = self._post('/tasks', json=request_data)

try:
Expand Down Expand Up @@ -100,7 +100,7 @@ def post_result(self, task_id, task_data=None, task_error=None):
elif task_error:
request_data["task_error"] = task_error

logging.getLogger('HTTP').debug("Posting results for task '%s': %s", task_id, request_data)
logging.getLogger('HTTP').info("Posting results for task '%s'", task_id)

uploaded = False
while not uploaded:
Expand Down
4 changes: 2 additions & 2 deletions slamon_agent/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _run_task(self, task, callback):
self._logger.debug('Executing task handler for task %s', task['task_id'])
result = handler(task['task_data'])

self._logger.debug('Task executed successfully: %s', task['task_id'])
self._logger.info('Task executed successfully: %s', task['task_id'])
callback(task['task_id'], task_data=result)

except Exception as e:
Expand All @@ -75,7 +75,7 @@ def submit_task(self, task, callback):
:param callback: callable that will receive results
"""
with self._lock:
self._thread_pool.submit(lambda: self._run_task(task, callback))
self._thread_pool.submit(self._run_task, task, callback)
self._active_executors += 1

def available_executors(self):
Expand Down

0 comments on commit 7914234

Please sign in to comment.