Skip to content

Commit

Permalink
Add options to config log file
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyao committed Jul 18, 2013
1 parent d8fc5cf commit d71abcc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions example_conf.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
29 changes: 29 additions & 0 deletions pyapns.tac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit d71abcc

Please sign in to comment.