R/W error with the glances.log file (issue #474)

This commit is contained in:
Nicolargo 2015-01-06 21:38:03 +01:00 committed by Alessio Sergi
parent 4788328759
commit 83b0a1fdd8
3 changed files with 22 additions and 1 deletions

6
NEWS
View File

@ -5,6 +5,8 @@ Glances Version 2.x
Version 2.3
===========
Enhancements and news features:
* Add actions on alerts (issue #132). It is now possible to run action (command line) by triggers. Action could containq {Mustache} {{tag}} (Mustache) with stat value.
* Add InfluxDB export module (--export-influxdb) (issue #455)
* Add Statsd export module (--export-statsd) (issue #465)
@ -13,6 +15,10 @@ Version 2.3
* Add the RAID plugin (issue #447)
* Add the Docker plugin (issue #440)
Bugs corrected:
* R/W error with the glances.log file (issue #474)
Version 2.2.1
=============

View File

@ -332,6 +332,8 @@ By default, the log file is under:
:Linux, \*BSD and OS X: ``/tmp/glances.log``
:Windows: ``%APPDATA%\Local\temp\glances.log``
If glances.log is not writable, a new file will be created and returned to the user console.
Anatomy Of The Application
==========================

View File

@ -71,14 +71,27 @@ LOGGING_CFG = {
}
def tempfile_name():
"""Return the tempfile name (full path)"""
ret = os.path.join(tempfile.gettempdir(), 'glances.log')
if os.access(ret, os.F_OK) and not os.access(ret, os.W_OK):
print("Warning: can't write logs to file {} (permission denied)".format(ret))
ret = tempfile.mkstemp(prefix='glances', suffix='.tmp', text=True)
print("Create a new log file: {}".format(ret[1]))
return ret[1]
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=os.path.join(tempfile.gettempdir(), 'glances.log'),
logging.basicConfig(filename=temp_path,
level=logging.DEBUG,
format='%(asctime)s -- %(levelname)s -- %(message)s')
return _logger