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 ``DEBUG`` messages can been logged using the ``-d`` option on the command
line. 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.
=========== ====== The file is automatically rotate when the size is higher than 1 MB.
``*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``.
If you want to use another system path or change the log message, you 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 can use your own logger configuration. First of all, you have to create

View File

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText. .\" 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 .SH NAME
glances \- An eye on your system 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 \fBDEBUG\fP messages can been logged using the \fB\-d\fP option on the command
line. line.
.sp .sp
By default, the \fBglances\-USERNAME.log\fP file is under the temporary directory: The location of the Glances depends of your operating system. You could
.TS displayed the Glances log file full path using the\(ga\(gaglances \-V\(ga\(ga command line.
center; .sp
|l|l|. The file is automatically rotate when the size is higher than 1 MB.
_
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
.sp .sp
If you want to use another system path or change the log message, you 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 can use your own logger configuration. First of all, you have to create

View File

@ -27,8 +27,27 @@ import tempfile
import logging import logging
import logging.config import logging.config
LOG_FILENAME = os.path.join(tempfile.gettempdir(), from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS, WSL
'glances-{}.log'.format(getpass.getuser())) 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 # Define the logging configuration
LOGGING_CFG = { LOGGING_CFG = {
@ -56,6 +75,8 @@ LOGGING_CFG = {
"file": { "file": {
"level": "DEBUG", "level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler", "class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1000000,
"backupCount": 3,
"formatter": "standard", "formatter": "standard",
"filename": LOG_FILENAME "filename": LOG_FILENAME
}, },

View File

@ -27,7 +27,7 @@ from glances import __version__, psutil_version
from glances.compat import input from glances.compat import input
from glances.config import Config from glances.config import Config
from glances.globals import WINDOWS from glances.globals import WINDOWS
from glances.logger import logger from glances.logger import logger, LOG_FILENAME
def disable(class_name, var): def disable(class_name, var):
@ -112,7 +112,7 @@ Examples of use:
def init_args(self): def init_args(self):
"""Init all the command line arguments.""" """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( parser = argparse.ArgumentParser(
prog='glances', prog='glances',
conflict_handler='resolve', conflict_handler='resolve',