提交 a51035a3 编写于 作者: N Nicolas Hennion

Add Logging class

上级 3c5975c5
......@@ -47,7 +47,7 @@ if psutil_version < psutil_min_version:
# Import Glances libs
# Note: others Glances libs will be imported optionally
from glances.core.glances_globals import gettext_domain, locale_dir
from glances.core.glances_globals import gettext_domain, locale_dir, logger
from glances.core.glances_main import GlancesMain
......@@ -58,6 +58,7 @@ def __signal_handler(signal, frame):
def end():
"""Stop Glances."""
logger.info("Stop Glances (with CTRL-C)")
if core.is_standalone():
# Stop the standalone (CLI)
standalone.end()
......@@ -93,6 +94,7 @@ def main():
# Glances can be ran in standalone, client or server mode
if core.is_standalone():
logger.info("Start Glances in standalone mode")
# Import the Glances standalone module
from glances.core.glances_standalone import GlancesStandalone
......@@ -105,6 +107,7 @@ def main():
standalone.serve_forever()
elif core.is_client():
logger.info("Start Glances in client mode")
# Import the Glances client module
from glances.core.glances_client import GlancesClient
......@@ -125,6 +128,7 @@ def main():
client.close()
elif core.is_server():
logger.info("Start Glances in server mode")
# Import the Glances server module
from glances.core.glances_server import GlancesServer
......@@ -147,6 +151,7 @@ def main():
server.server_close()
elif core.is_webserver():
logger.info("Start Glances in web server mode")
# Import the Glances web server module
from glances.core.glances_webserver import GlancesWebServer
......
......@@ -22,6 +22,8 @@
import os
import sys
from glances.core.glances_logging import glancesLogger
# Global information
appname = 'glances'
version = __import__('glances').__version__
......@@ -58,6 +60,9 @@ elif os.path.exists(sys_i18n_path):
else:
locale_dir = None
# Create and init the logging instance
logger = glancesLogger()
# Instances shared between all Glances scripts
# ============================================
......
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Custom logging class"""
import logging
import logging.config
# 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'
}
},
'handlers': {
'file': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'formatter': 'standard',
'filename': '/tmp/glances.log'
},
'console':{
'level':'CRITICAL',
'class':'logging.StreamHandler',
'formatter': 'standard'
}
},
'loggers': {
'debug': {
'handlers':['file', 'console'],
'level':'DEBUG',
},
'verbose': {
'handlers': ['file', 'console'],
'level': 'INFO'
},
'standard': {
'handlers': ['file'],
'level': 'INFO'
}
}
}
def glancesLogger():
_logger = logging.getLogger()
logging.config.dictConfig(LOGGING_CFG)
return _logger
......@@ -23,7 +23,7 @@
import sys
# Import Glances lib
from glances.core.glances_globals import glances_logs, glances_processes, is_windows
from glances.core.glances_globals import glances_logs, glances_processes, is_windows, logger
from glances.core.glances_timer import Timer
# Import curses lib for "normal" operating system and consolelog for Windows
......@@ -181,6 +181,7 @@ class GlancesCurses(object):
if self.pressedkey == ord('\x1b') or self.pressedkey == ord('q'):
# 'ESC'|'q' > Quit
self.end()
logger.info("Stop Glances")
sys.exit(0)
elif self.pressedkey == ord('1'):
# '1' > Switch between CPU and PerCPU information
......
......@@ -41,6 +41,9 @@ class Plugin(GlancesPlugin):
# We want to display the stat in the curse interface
self.display_curse = True
# Set the message position
self.set_align('bottom')
# Init the stats
self.reset()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册