diff --git a/NEWS b/NEWS index 81ee3911..6480042c 100644 --- a/NEWS +++ b/NEWS @@ -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 ============= diff --git a/docs/glances-doc.rst b/docs/glances-doc.rst index c86b1c7b..0f33a063 100644 --- a/docs/glances-doc.rst +++ b/docs/glances-doc.rst @@ -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 ========================== diff --git a/glances/core/glances_logging.py b/glances/core/glances_logging.py index 74518f3e..82a8a9d3 100644 --- a/glances/core/glances_logging.py +++ b/glances/core/glances_logging.py @@ -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