25
25
h = logging.FileHandler(filename)
29
29
def setup_logging(home, config, foreground):
30
30
# i hate that stupid logging config format, so just set up logging here.
32
32
log_folder = os.path.join(home, 'logs')
33
33
if not os.path.exists(log_folder):
34
34
os.mkdir(log_folder)
36
36
f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s',
38
38
debug_log = make_handler(config, os.path.join(log_folder, 'debug.log'))
47
47
access_log = make_handler(config, os.path.join(log_folder, 'access.log'))
48
48
access_log.setLevel(logging.INFO)
49
49
access_log.setFormatter(f)
51
51
logging.getLogger('').addHandler(debug_log)
52
52
logging.getLogger('turbogears.access').addHandler(access_log)
53
53
logging.getLogger('turbogears.controllers').setLevel(logging.INFO)
56
56
logging.getLogger('').addHandler(stdout_log)
66
66
options, args = parser.parse_args()
68
68
parser.error('No filename arguments are used, only options.')
71
71
home = os.path.realpath(os.path.dirname(__file__))
72
72
pidfile = os.path.join(home, 'loggerhead.pid')
75
75
if daemon.is_running(pidfile):
77
77
sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (pidfile,))
79
79
# read loggerhead config
81
81
from configobj import ConfigObj
82
82
config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
83
83
extra_path = config.get('bzrpath', None)
85
85
sys.path.insert(0, extra_path)
87
87
turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config")
89
89
potential_overrides = [ ('server.socket_port', int), ('server.webpath', str), ('server.thread_pool', int), ('server.socket_host' ,str) ]
90
90
for key, keytype in potential_overrides:
91
91
value = config.get(key, None)
92
92
if value is not None:
93
93
value = keytype(value)
94
94
turbogears.config.update({ key: value })
96
96
if not options.foreground:
97
97
sys.stderr.write('\n')
98
98
sys.stderr.write('Launching loggerhead into the background.\n')
99
99
sys.stderr.write('PID file: %s\n' % (pidfile,))
100
100
sys.stderr.write('\n')
102
102
daemon.daemonize(pidfile, home)
104
104
setup_logging(home, config, foreground=options.foreground)
106
106
log = logging.getLogger('loggerhead')
107
107
log.info('Starting up...')
109
109
from loggerhead.controllers import Root
111
111
Root = Root(config)
114
114
turbogears.start_server(Root)