summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2019-12-26 11:09:14 +0100
committernicolargo <nicolas@nicolargo.com>2019-12-26 11:09:14 +0100
commitecb9db9c868ec753b2cb71293c22663c203c4192 (patch)
tree652082b10546e2bcc3da3c93a2a31e77a34e8e40
parent57ffb712f8d33ad4ca2611d5a2922a9e44c8661a (diff)
parent9a10c9217830d1a54b85638d6abb8667543e12b6 (diff)
Merge branch 'issue1575' into develop
-rw-r--r--docs/config.rst11
-rw-r--r--docs/man/glances.130
-rw-r--r--glances/logger.py25
-rw-r--r--glances/main.py4
4 files changed, 33 insertions, 37 deletions
diff --git a/docs/config.rst b/docs/config.rst
index 875a2b35..00c54851 100644
--- a/docs/config.rst
+++ b/docs/config.rst
@@ -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
diff --git a/docs/man/glances.1 b/docs/man/glances.1
index 4fb8ce31..a7539c3c 100644
--- a/docs/man/glances.1
+++ b/docs/man/glances.1
@@ -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
diff --git a/glances/logger.py b/glances/logger.py
index 472b264f..10b2ee7e 100644
--- a/glances/logger.py
+++ b/glances/logger.py
@@ -27,8 +27,27 @@ import tempfile
import logging
import logging.config
-LOG_FILENAME = os.path.join(tempfile.gettempdir(),
- 'glances-{}.log'.format(getpass.getuser()))
+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
LOGGING_CFG = {
@@ -56,6 +75,8 @@ LOGGING_CFG = {
"file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
+ "maxBytes": 1000000,
+ "backupCount": 3,
"formatter": "standard",
"filename": LOG_FILENAME
},
diff --git a/glances/main.py b/glances/main.py
index 0b5f070b..dad17e6f 100644
--- a/glances/main.py
+++ b/glances/main.py
@@ -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',