Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
a51035a3
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a51035a3
编写于
7月 02, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Logging class
上级
3c5975c5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
86 addition
and
2 deletion
+86
-2
glances/__init__.py
glances/__init__.py
+6
-1
glances/core/glances_globals.py
glances/core/glances_globals.py
+5
-0
glances/core/glances_logging.py
glances/core/glances_logging.py
+70
-0
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+2
-1
glances/plugins/glances_alert.py
glances/plugins/glances_alert.py
+3
-0
未找到文件。
glances/__init__.py
浏览文件 @
a51035a3
...
...
@@ -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
...
...
glances/core/glances_globals.py
浏览文件 @
a51035a3
...
...
@@ -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
# ============================================
...
...
glances/core/glances_logging.py
0 → 100644
浏览文件 @
a51035a3
# -*- 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
glances/outputs/glances_curses.py
浏览文件 @
a51035a3
...
...
@@ -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
...
...
glances/plugins/glances_alert.py
浏览文件 @
a51035a3
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录