提交 4d1ef9bb 编写于 作者: N Nicolargo

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

上级 0bd5993a
......@@ -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
=============
......
......@@ -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
==========================
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册