log file under public/shared tmp/ folders must not have deterministic name #1575

pull/1580/head
nicolargo 2019-12-26 11:08:57 +01:00
parent 57ffb712f8
commit 9a10c92178
4 changed files with 33 additions and 37 deletions

View File

@ -115,15 +115,10 @@ Glances logs all of its internal messages to a log file.
``DEBUG`` messages can been logged using the ``-d`` option on the command
line.
By default, the ``glances-USERNAME.log`` file is under the temporary directory:
The location of the Glances depends of your operating system. You could
displayed the Glances log file full path using the``glances -V`` command line.
=========== ======
``*nix`` /tmp
``Windows`` %TEMP%
=========== ======
- On Windows XP, ``%TEMP%`` is: ``C:\Documents and Settings\<USERNAME>\Local Settings\Temp``.
- On Windows Vista and later: ``C:\Users\<USERNAME>\AppData\Local\Temp``.
The file is automatically rotate when the size is higher than 1 MB.
If you want to use another system path or change the log message, you
can use your own logger configuration. First of all, you have to create

View File

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Nov 24, 2019" "3.1.4_BETA" "Glances"
.TH "GLANCES" "1" "Dec 26, 2019" "3.1.4_BETA" "Glances"
.SH NAME
glances \- An eye on your system
.
@ -670,30 +670,10 @@ Glances logs all of its internal messages to a log file.
\fBDEBUG\fP messages can been logged using the \fB\-d\fP option on the command
line.
.sp
By default, the \fBglances\-USERNAME.log\fP file is under the temporary directory:
.TS
center;
|l|l|.
_
T{
\fB*nix\fP
T} T{
/tmp
T}
_
T{
\fBWindows\fP
T} T{
%TEMP%
T}
_
.TE
.INDENT 0.0
.IP \(bu 2
On Windows XP, \fB%TEMP%\fP is: \fBC:\eDocuments and Settings\e<USERNAME>\eLocal Settings\eTemp\fP\&.
.IP \(bu 2
On Windows Vista and later: \fBC:\eUsers\e<USERNAME>\eAppData\eLocal\eTemp\fP\&.
.UNINDENT
The location of the Glances depends of your operating system. You could
displayed the Glances log file full path using the\(ga\(gaglances \-V\(ga\(ga command line.
.sp
The file is automatically rotate when the size is higher than 1 MB.
.sp
If you want to use another system path or change the log message, you
can use your own logger configuration. First of all, you have to create

View File

@ -27,7 +27,26 @@ import tempfile
import logging
import logging.config
LOG_FILENAME = os.path.join(tempfile.gettempdir(),
from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS, WSL
from glances.globals import safe_makedirs
# Choose the good place for the log file (see issue #1575)
# Default root path
if 'HOME' in os.environ:
_XDG_CACHE_HOME = os.path.join(os.environ['HOME'], '.local', 'share')
else:
_XDG_CACHE_HOME = ''
# Define the glances log file
if 'XDG_CACHE_HOME' in os.environ \
and os.path.isdir(os.environ['XDG_CACHE_HOME']) \
and os.access(os.environ['XDG_CACHE_HOME'], os.W_OK):
safe_makedirs(os.path.join(os.environ['XDG_CACHE_HOME'], 'glances'))
LOG_FILENAME = os.path.join(os.environ['XDG_CACHE_HOME'], 'glances', 'glances.log')
elif os.path.isdir(_XDG_CACHE_HOME) and os.access(_XDG_CACHE_HOME, os.W_OK):
safe_makedirs(os.path.join(_XDG_CACHE_HOME, 'glances'))
LOG_FILENAME = os.path.join(_XDG_CACHE_HOME, 'glances', 'glances.log')
else:
LOG_FILENAME = os.path.join(tempfile.gettempdir(),
'glances-{}.log'.format(getpass.getuser()))
# Define the logging configuration
@ -56,6 +75,8 @@ LOGGING_CFG = {
"file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1000000,
"backupCount": 3,
"formatter": "standard",
"filename": LOG_FILENAME
},

View File

@ -27,7 +27,7 @@ from glances import __version__, psutil_version
from glances.compat import input
from glances.config import Config
from glances.globals import WINDOWS
from glances.logger import logger
from glances.logger import logger, LOG_FILENAME
def disable(class_name, var):
@ -112,7 +112,7 @@ Examples of use:
def init_args(self):
"""Init all the command line arguments."""
version = "Glances v" + __version__ + " with psutil v" + psutil_version
version = 'Glances v{} with PsUtil v{}\nLog file: {}'.format(__version__, psutil_version, LOG_FILENAME)
parser = argparse.ArgumentParser(
prog='glances',
conflict_handler='resolve',