mirror of https://github.com/nicolargo/glances
Fix logging support for Python 2.6
Use logutils when running on Python 2.6. Close #512.pull/532/head^2
parent
7a95094068
commit
6b3c47b826
|
@ -20,7 +20,12 @@
|
|||
"""Custom logging class"""
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
try:
|
||||
# Python 2.6
|
||||
from logutils.dictconfig import dictConfig
|
||||
except ImportError:
|
||||
# Python >= 2.7
|
||||
from logging.config import dictConfig
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
@ -86,15 +91,9 @@ def glances_logger():
|
|||
"""Build and return the logger"""
|
||||
temp_path = tempfile_name()
|
||||
_logger = logging.getLogger()
|
||||
try:
|
||||
LOGGING_CFG['handlers']['file']['filename'] = temp_path
|
||||
logging.config.dictConfig(LOGGING_CFG)
|
||||
except AttributeError:
|
||||
# dictConfig is only available for Python 2.7 or higher
|
||||
# Minimal configuration for Python 2.6
|
||||
logging.basicConfig(filename=temp_path,
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s -- %(levelname)s -- %(message)s')
|
||||
LOGGING_CFG['handlers']['file']['filename'] = temp_path
|
||||
dictConfig(LOGGING_CFG)
|
||||
|
||||
return _logger
|
||||
|
||||
logger = glances_logger()
|
||||
|
|
5
setup.py
5
setup.py
|
@ -31,7 +31,6 @@ def get_data_files():
|
|||
conf_path = os.path.join(os.environ.get('APPDATA'), 'glances')
|
||||
else: # Unix-like + per-user install
|
||||
conf_path = os.path.join('etc', 'glances')
|
||||
|
||||
data_files.append((conf_path, ['conf/glances.conf']))
|
||||
|
||||
for mo in glob.glob('i18n/*/LC_MESSAGES/*.mo'):
|
||||
|
@ -45,8 +44,8 @@ def get_requires():
|
|||
requires = ['psutil>=2.0.0']
|
||||
if sys.platform.startswith('win'):
|
||||
requires += ['colorconsole']
|
||||
if sys.version_info < (2, 7):
|
||||
requires += ['argparse']
|
||||
if sys.version_info == (2, 6):
|
||||
requires += ['argparse', 'logutils']
|
||||
|
||||
return requires
|
||||
|
||||
|
|
Loading…
Reference in New Issue