Skip to content

Commit

Permalink
优化日志记录
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdon committed Mar 29, 2017
1 parent 66a7456 commit 72955a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 54 deletions.
49 changes: 0 additions & 49 deletions logger.conf

This file was deleted.

11 changes: 6 additions & 5 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
pidfile = open(os.path.realpath(__file__), "r")
################################################
# logging config
logger_conf_file = os.path.abspath(os.path.join(current_dir, "logger.conf"))
logging.config.fileConfig(logger_conf_file)
logger = logging.getLogger("monitor")
monitor_log = os.path.abspath(os.path.join(current_dir, "monitor.log"))
logger.addHandler(logging.FileHandler(monitor_log))

logger = logging.getLogger()
handler = logging.FileHandler(monitor_log)
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
try:

# 创建一个排他锁,为了避免同时操作文件,需要程序自己来检查该文件是否已经被加锁。这里如果检查到加锁了,进程会被阻塞
Expand Down

0 comments on commit 72955a0

Please sign in to comment.