Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions modules/nginit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
APP_AUTHOR = 'qing.chen'

'''
处理程序的路径,可能需要手动更改
处理程序的路径,默认使用当前程序所在目录
'''
APP_PATH = '/data/ng-mini'
#APP_PATH = os.path.abspath('.')
APP_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))

CONFIG_PATH = os.path.join(APP_PATH ,'etc')
'''
Expand All @@ -40,7 +39,10 @@
cf = ConfigParser.ConfigParser()
cf.read(CONFIG_PATH + '/ng.conf')
#是不是要记录日志
LOGED = cf.get('log','log')
try:
LOGED = cf.get('log','log').lower() in ('yes','true','1','on')
except:
LOGED = False
#日志的记录路径是什么,默认在程序目录下的log目录
try:
LOG_PATH = cf.get('log','logpath')
Expand Down Expand Up @@ -73,7 +75,7 @@
try:
YAML_PATH = CONFIG_PATH + '/' + cf.get('base','yaml_path')
except:
YAML_PATH = ' '
YAML_PATH = CONFIG_PATH + '/conf.d'

#需要作图的app
try:
Expand Down
17 changes: 10 additions & 7 deletions modules/nglog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ def nglog():
'''
处理ng的日志相关的函数
'''
logger = logging.getLogger()
logger.setLevel(getattr(logging, nginit.LOG_LEVEL, logging.INFO))
if nginit.LOGED:
logger = logging.getLogger()
logger.setLevel(getattr(logging,nginit.LOG_LEVEL))
File = logging.handlers.RotatingFileHandler(nginit.LOG_PATH,maxBytes=1024*1024,backupCount=5)
Format = logging.Formatter("%(asctime)s %(levelname)s - %(message)s","%Y-%m-%d %H:%M:%S")
File.setFormatter(Format)
logger.addHandler(File)
return logger
try:
File = logging.handlers.RotatingFileHandler(nginit.LOG_PATH,maxBytes=1024*1024,backupCount=5)
Format = logging.Formatter("%(asctime)s %(levelname)s - %(message)s","%Y-%m-%d %H:%M:%S")
File.setFormatter(Format)
logger.addHandler(File)
except Exception:
pass
return logger

log = nglog()

Expand Down