diff --git a/example_conf.json b/example_conf.json index cbc7403..ab205c4 100644 --- a/example_conf.json +++ b/example_conf.json @@ -1,5 +1,9 @@ { "host": "localhost", + "log_file_name": "pyapns.log", + "log_file_dir": ".", + "log_file_rotate_length": 1000000000, + "log_file_max_rotate": 10, "port": 7077, "rest_port": 8088, "autoprovision": [ diff --git a/pyapns.tac b/pyapns.tac index fd6404c..ff8b1bf 100644 --- a/pyapns.tac +++ b/pyapns.tac @@ -6,6 +6,8 @@ config_file = '/path/to/config/pyapns_conf.json' # you don't need to change anything below this line really import twisted.application, twisted.web, twisted.application.internet +from twisted.python.logfile import LogFile +from twisted.python.log import ILogObserver, FileLogObserver import pyapns.server, pyapns._json import pyapns.rest_service, pyapns.model import os @@ -33,7 +35,34 @@ if 'autoprovision' in config: timeout=app['timeout'] ) +if 'log_file_name' in config: + log_file_name = config['log_file_name'] +else: + log_file_name = 'twistd.log' + +if 'log_file_dir' in config: + log_file_dir = config['log_file_dir'] +else: + log_file_dir = '.' + +if 'log_file_rotate_length' in config: + log_file_rotate_length = config['log_file_rotate_length'] +else: + log_file_rotate_length = 1000000 + +if 'log_file_mode' in config: + log_file_mode = config['log_file_mode'] +else: + log_file_mode = None + +if 'log_file_max_rotate' in config: + log_file_max_rotate = config['log_file_max_rotate'] +else: + log_file_max_rotate = None + application = twisted.application.service.Application("pyapns application") +logfile = LogFile(log_file_name, log_file_dir, log_file_rotate_length, log_file_mode, log_file_max_rotate) +application.setComponent(ILogObserver, FileLogObserver(logfile).emit) if 'host' in config: host = config['host']