Skip to content

Commit

Permalink
Module log
Browse files Browse the repository at this point in the history
  • Loading branch information
xlui committed Oct 4, 2018
1 parent f9d0a4f commit ea24105
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
config.json
# ignore python cache
__pycache__/
*.log
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,8 @@ python:
- "3.7-dev"
services:
- redis-server
env:
EFUTURE_CONFIG=`pwd`/config-example.json
install:
pip install -r requirements.txt
script:
Expand Down
4 changes: 3 additions & 1 deletion config-example.json
Expand Up @@ -5,5 +5,7 @@
"smtp_port": "587",
"redis_address": "127.0.0.1:6379",
"redis_password": "",
"redis_db": 0
"redis_db": 0,
"log_path": "/tmp/eFuture.log",
"log_level": "DEBUG"
}
2 changes: 2 additions & 0 deletions config/config.py
Expand Up @@ -10,3 +10,5 @@
port = configuration['smtp_port']
username = configuration['username']
password = configuration['password']
logPath = configuration['log_path']
logLevel = configuration['log_level']
Empty file added log/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions log/log.py
@@ -0,0 +1,14 @@
import logging
from logging.handlers import RotatingFileHandler
from config.config import logPath, logLevel

# 10MB each log file
handler = RotatingFileHandler(logPath, maxBytes=10 * 1024 * 1024, backupCount=5)
fmt = '%(asctime)s - %(filename)s:%(lineno)s - func: [%(name)s] - %(message)s'
formatter = logging.Formatter(fmt)
handler.setFormatter(formatter)

logger = logging.getLogger('eFuture')
logger.addHandler(handler)
logger.setLevel(logLevel)
logger.debug('debug')

0 comments on commit ea24105

Please sign in to comment.