Commit 4b1a745b authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Merge branch 'master' into api

parents ec56f9ca 2feba888
......@@ -4,47 +4,10 @@ from synnefo.lib.pool.http import get_http_connection
from urlparse import urlparse
from commissioning import Callpoint, CallError
from commissioning.utils.clijson import clijson
import logging
from commissioning.utils.debug import debug
from json import loads as json_loads, dumps as json_dumps
_logger = None
def init_logger_file(name, level='DEBUG'):
logger = logging.getLogger(name)
handler = logging.FileHandler(name + '.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
level = getattr(logging, level, logging.DEBUG)
logger.setLevel(level)
global _logger
_logger = logger
return logger
def init_logger_stderr(name, level='DEBUG'):
logger = logging.getLogger(name)
from sys import stderr
handler = logging.StreamHandler(stderr)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
level = getattr(logging, level, logging.DEBUG)
logger.setLevel(level)
global _logger
_logger = logger
return logger
def debug(fmt, *args):
global _logger
if _logger is None:
init_logger_stderr('logger')
_logger.setLevel(logging.DEBUG)
_logger.debug(fmt % args)
class HTTP_API_Client(Callpoint):
"""Synchronous http client for quota holder API"""
......
#!/usr/bin/env python
import logging
from os import environ
_logger = None
def init_logger_file(name, level='DEBUG'):
logger = logging.getLogger(name)
handler = logging.FileHandler(name + '.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
level = getattr(logging, level, logging.DEBUG)
logger.setLevel(level)
global _logger
_logger = logger
return logger
def init_logger_stderr(name, level='DEBUG'):
logger = logging.getLogger(name)
from sys import stderr
handler = logging.StreamHandler(stderr)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
level = getattr(logging, level, logging.DEBUG)
logger.setLevel(level)
global _logger
_logger = logger
return logger
def debug(fmt, *args):
global _logger
if _logger is None:
init_logger_stderr('logger', get_level())
_logger.debug(fmt % args)
def get_level(default='INFO'):
try:
return environ['DEBUG_LEVEL']
except:
return default
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