Revision f47417e7
b/docs/conf.py | ||
---|---|---|
24 | 24 |
PooledHTTPConnection |
25 | 25 |
except ImportError: |
26 | 26 |
stderr.write("`objpool` package is required to build kamaki docs.\n") |
27 |
raise |
|
27 |
# raise
|
|
28 | 28 |
|
29 | 29 |
path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')) |
30 | 30 |
|
b/kamaki/cli/__init__.py | ||
---|---|---|
388 | 388 |
if parser.arguments['version'].value: |
389 | 389 |
exit(0) |
390 | 390 |
|
391 |
log_file = parser.arguments['config'].get('global', 'log_file') |
|
392 |
if log_file: |
|
393 |
from kamaki.logger import set_log_filename |
|
394 |
set_log_filename(log_file) |
|
395 |
|
|
391 | 396 |
_init_session(parser.arguments) |
392 | 397 |
|
393 | 398 |
from kamaki.cli.utils import suggest_missing |
b/kamaki/cli/commands/__init__.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A.command |
33 | 33 |
|
34 |
import logging
|
|
34 |
from kamaki import logger
|
|
35 | 35 |
|
36 |
sendlog = logging.getLogger('clients.send')
|
|
37 |
recvlog = logging.getLogger('clients.recv')
|
|
36 |
logger.add_file_logger('cli', __name__, filename=logger.get_log_filename())
|
|
37 |
sendlog = logger.get_logger('cli')
|
|
38 | 38 |
|
39 | 39 |
|
40 | 40 |
class _command_init(object): |
... | ... | |
49 | 49 |
except KeyError: |
50 | 50 |
pass |
51 | 51 |
|
52 |
def _update_low_level_log(self):
|
|
52 |
def _set_log_params(self):
|
|
53 | 53 |
try: |
54 | 54 |
self.client.LOG_TOKEN, self.client.LOG_DATA = ( |
55 | 55 |
self['config'].get('global', 'log_token') == 'on', |
b/kamaki/cli/commands/astakos_cli.py | ||
---|---|---|
51 | 51 |
base_url = self.config.get('astakos', 'url')\ |
52 | 52 |
or self.config.get('global', 'url') |
53 | 53 |
self.client = AstakosClient(base_url=base_url, token=token) |
54 |
self._update_low_level_log()
|
|
54 |
self._set_log_params()
|
|
55 | 55 |
self._update_max_threads() |
56 | 56 |
|
57 | 57 |
def main(self): |
b/kamaki/cli/commands/cyclades_cli.py | ||
---|---|---|
72 | 72 |
base_url = self.config.get(service, 'url')\ |
73 | 73 |
or self.config.get('global', 'url') |
74 | 74 |
self.client = CycladesClient(base_url=base_url, token=token) |
75 |
self._update_low_level_log()
|
|
75 |
self._set_log_params()
|
|
76 | 76 |
self._update_max_threads() |
77 | 77 |
|
78 | 78 |
def main(self): |
b/kamaki/cli/commands/image_cli.py | ||
---|---|---|
59 | 59 |
or self.config.get('compute', 'url')\ |
60 | 60 |
or self.config.get('global', 'url') |
61 | 61 |
self.client = ImageClient(base_url=base_url, token=token) |
62 |
self._update_low_level_log()
|
|
62 |
self._set_log_params()
|
|
63 | 63 |
self._update_max_threads() |
64 | 64 |
|
65 | 65 |
def main(self): |
b/kamaki/cli/commands/pithos_cli.py | ||
---|---|---|
173 | 173 |
token=self.token, |
174 | 174 |
account=self.account, |
175 | 175 |
container=self.container) |
176 |
self._update_low_level_log()
|
|
176 |
self._set_log_params()
|
|
177 | 177 |
self._update_max_threads() |
178 | 178 |
|
179 | 179 |
def main(self): |
b/kamaki/clients/__init__.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
from objpool.http import PooledHTTPConnection |
44 | 44 |
|
45 |
from kamaki.clients.utils import logger
|
|
45 |
from kamaki import logger |
|
46 | 46 |
|
47 |
DEBUG_LOG = logger.get_log_filename()
|
|
47 |
LOG_FILE = logger.get_log_filename()
|
|
48 | 48 |
TIMEOUT = 60.0 # seconds |
49 | 49 |
HTTP_METHODS = ['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'COPY', 'MOVE'] |
50 | 50 |
|
51 |
logger.add_file_logger('clients.send', __name__, filename=DEBUG_LOG)
|
|
51 |
logger.add_file_logger('clients.send', __name__, filename=LOG_FILE)
|
|
52 | 52 |
sendlog = logger.get_logger('clients.send') |
53 |
sendlog.debug('Logging location: %s' % DEBUG_LOG)
|
|
53 |
sendlog.debug('Logging location: %s' % LOG_FILE)
|
|
54 | 54 |
|
55 |
logger.add_file_logger('data.send', __name__, filename=DEBUG_LOG)
|
|
55 |
logger.add_file_logger('data.send', __name__, filename=LOG_FILE)
|
|
56 | 56 |
datasendlog = logger.get_logger('data.send') |
57 | 57 |
|
58 |
logger.add_file_logger('clients.recv', __name__, filename=DEBUG_LOG)
|
|
58 |
logger.add_file_logger('clients.recv', __name__, filename=LOG_FILE)
|
|
59 | 59 |
recvlog = logger.get_logger('clients.recv') |
60 | 60 |
|
61 |
logger.add_file_logger('data.recv', __name__, filename=DEBUG_LOG)
|
|
61 |
logger.add_file_logger('data.recv', __name__, filename=LOG_FILE)
|
|
62 | 62 |
datarecvlog = logger.get_logger('data.recv') |
63 | 63 |
|
64 |
logger.add_file_logger('ClientError', __name__, filename=DEBUG_LOG)
|
|
64 |
logger.add_file_logger('ClientError', __name__, filename=LOG_FILE)
|
|
65 | 65 |
clienterrorlog = logger.get_logger('ClientError') |
66 | 66 |
|
67 | 67 |
|
... | ... | |
186 | 186 |
headers=self.headers, |
187 | 187 |
body=self.data) |
188 | 188 |
self.log() |
189 |
keep_trying = 60.0
|
|
189 |
keep_trying = TIMEOUT
|
|
190 | 190 |
while keep_trying > 0: |
191 | 191 |
try: |
192 | 192 |
return conn.getresponse() |
/dev/null | ||
---|---|---|
1 |
# Copyright 2013 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
import logging |
|
35 |
|
|
36 |
|
|
37 |
def get_log_filename(filename=( |
|
38 |
'/var/log/kamaki.log', |
|
39 |
'/var/log/kamaki/clients.log', |
|
40 |
'/tmp/kamaki.log', |
|
41 |
'kamaki.log')): |
|
42 |
if not (isinstance(filename, list) or isinstance(filename, tuple)): |
|
43 |
filename = (filename,) |
|
44 |
for logfile in filename: |
|
45 |
try: |
|
46 |
with open(logfile) as f: |
|
47 |
f.seek(0) |
|
48 |
except IOError: |
|
49 |
continue |
|
50 |
return logfile |
|
51 |
print('Failed to open any logging locations, file-logging aborted') |
|
52 |
|
|
53 |
|
|
54 |
def add_file_logger( |
|
55 |
name, caller, |
|
56 |
level=logging.DEBUG, prefix='', filename='/tmp/kamaki.log'): |
|
57 |
try: |
|
58 |
assert caller and filename |
|
59 |
logger = logging.getLogger(name) |
|
60 |
h = logging.FileHandler(filename) |
|
61 |
fmt = logging.Formatter( |
|
62 |
'%(asctime)s ' + caller + ' %(name)s-%(levelname)s: %(message)s') |
|
63 |
h.setFormatter(fmt) |
|
64 |
logger.addHandler(h) |
|
65 |
logger.setLevel(level) |
|
66 |
except Exception: |
|
67 |
pass |
|
68 |
|
|
69 |
|
|
70 |
def get_logger(name): |
|
71 |
return logging.getLogger(name) |
b/kamaki/logger.py | ||
---|---|---|
1 |
# Copyright 2013 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
33 |
|
|
34 |
import logging |
|
35 |
|
|
36 |
|
|
37 |
LOG_FILE = [ |
|
38 |
'/var/log/kamaki.log', |
|
39 |
'/var/log/kamaki/clients.log', |
|
40 |
'/tmp/kamaki.log', |
|
41 |
'kamaki.log'] |
|
42 |
|
|
43 |
|
|
44 |
def get_log_filename(): |
|
45 |
for logfile in LOG_FILE: |
|
46 |
try: |
|
47 |
with open(logfile, 'w+') as f: |
|
48 |
f.seek(0) |
|
49 |
except IOError: |
|
50 |
continue |
|
51 |
return logfile |
|
52 |
print('Failed to open any logging locations, file-logging aborted') |
|
53 |
|
|
54 |
|
|
55 |
def set_log_filename(filename): |
|
56 |
global LOG_FILE |
|
57 |
LOG_FILE = [filename] + LOG_FILE |
|
58 |
|
|
59 |
|
|
60 |
def add_file_logger( |
|
61 |
name, caller, |
|
62 |
level=logging.DEBUG, prefix='', filename='/tmp/kamaki.log'): |
|
63 |
try: |
|
64 |
assert caller and filename |
|
65 |
logger = logging.getLogger(name) |
|
66 |
h = logging.FileHandler(filename) |
|
67 |
fmt = logging.Formatter( |
|
68 |
'%(asctime)s ' + caller + ' %(name)s-%(levelname)s: %(message)s') |
|
69 |
h.setFormatter(fmt) |
|
70 |
logger.addHandler(h) |
|
71 |
logger.setLevel(level) |
|
72 |
except Exception: |
|
73 |
pass |
|
74 |
|
|
75 |
|
|
76 |
def get_logger(name): |
|
77 |
return logging.getLogger(name) |
Also available in: Unified diff