/usr/share/cagefs-skeleton/lib/python3.9/site-packages/glances
# -*- coding: utf-8 -*- # # This file is part of Glances. # # SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com> # # SPDX-License-Identifier: LGPL-3.0-only # """Custom logger class.""" import os import json import getpass import tempfile import logging import logging.config 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 = { "version": 1, "disable_existing_loggers": "False", "root": {"level": "INFO", "handlers": ["file", "console"]}, "formatters": { "standard": {"format": "%(asctime)s -- %(levelname)s -- %(message)s"}, "short": {"format": "%(levelname)s -- %(message)s"}, "long": {"format": "%(asctime)s -- %(levelname)s -- %(message)s (%(funcName)s in %(filename)s)"}, "free": {"format": "%(message)s"}, }, "handlers": { "file": { "level": "DEBUG", "class": "logging.handlers.RotatingFileHandler", "maxBytes": 1000000, "backupCount": 3, "formatter": "standard", "filename": LOG_FILENAME, }, "console": {"level": "CRITICAL", "class": "logging.StreamHandler", "formatter": "free"}, }, "loggers": { "debug": {"handlers": ["file", "console"], "level": "DEBUG"}, "verbose": {"handlers": ["file", "console"], "level": "INFO"}, "standard": {"handlers": ["file"], "level": "INFO"}, "requests": {"handlers": ["file", "console"], "level": "ERROR"}, "elasticsearch": {"handlers": ["file", "console"], "level": "ERROR"}, "elasticsearch.trace": {"handlers": ["file", "console"], "level": "ERROR"}, }, } def glances_logger(env_key='LOG_CFG'): """Build and return the logger. env_key define the env var where a path to a specific JSON logger could be defined :return: logger -- Logger instance """ _logger = logging.getLogger() # By default, use the LOGGING_CFG logger configuration config = LOGGING_CFG # Check if a specific configuration is available user_file = os.getenv(env_key, None) if user_file and os.path.exists(user_file): # A user file as been defined. Use it... with open(user_file, 'rt') as f: config = json.load(f) # Load the configuration logging.config.dictConfig(config) return _logger logger = glances_logger()
.
Edit
..
Edit
__init__.py
Edit
__main__.py
Edit
__pycache__
Edit
actions.py
Edit
amps
Edit
amps_list.py
Edit
attribute.py
Edit
autodiscover.py
Edit
client.py
Edit
client_browser.py
Edit
compat.py
Edit
config.py
Edit
cpu_percent.py
Edit
events.py
Edit
exports
Edit
filter.py
Edit
folder_list.py
Edit
globals.py
Edit
history.py
Edit
logger.py
Edit
main.py
Edit
outdated.py
Edit
outputs
Edit
password.py
Edit
password_list.py
Edit
plugins
Edit
ports_list.py
Edit
processes.py
Edit
programs.py
Edit
secure.py
Edit
server.py
Edit
snmp.py
Edit
standalone.py
Edit
static_list.py
Edit
stats.py
Edit
stats_client.py
Edit
stats_client_snmp.py
Edit
stats_server.py
Edit
thresholds.py
Edit
timer.py
Edit
web_list.py
Edit
webserver.py
Edit