16
def setup_logging(home, foreground):
17
# i hate that stupid logging config format, so just set up logging here.
19
log_folder = os.path.join(home, 'logs')
20
if not os.path.exists(log_folder):
23
f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s',
25
debug_log = logging.FileHandler(os.path.join(log_folder, 'debug.log'))
26
debug_log.setLevel(logging.DEBUG)
27
debug_log.setFormatter(f)
29
stdout_log = logging.StreamHandler(sys.stdout)
30
stdout_log.setLevel(logging.DEBUG)
31
stdout_log.setFormatter(f)
32
f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s',
34
access_log = logging.FileHandler(os.path.join(log_folder, 'access.log'))
35
access_log.setLevel(logging.INFO)
36
access_log.setFormatter(f)
38
logging.getLogger('').addHandler(debug_log)
39
logging.getLogger('turbogears.access').addHandler(access_log)
40
logging.getLogger('turbogears.controllers').setLevel(logging.INFO)
43
logging.getLogger('').addHandler(stdout_log)
49
if sys.argv[1] == '-f':
52
14
home = os.path.realpath(os.path.dirname(__file__))
53
15
pidfile = os.path.join(home, 'loggerhead.pid')
55
17
# read loggerhead config
57
19
from configobj import ConfigObj
58
config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
20
config = sys._loggerhead_config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
59
21
extra_path = config.get('bzrpath', None)
61
23
sys.path.insert(0, extra_path)
69
31
value = keytype(value)
70
32
turbogears.config.update({ key: value })
73
sys.stderr.write('\n')
74
sys.stderr.write('Launching loggerhead into the background.\n')
75
sys.stderr.write('PID file: %s\n' % (pidfile,))
76
sys.stderr.write('\n')
78
from loggerhead.daemon import daemonize
79
daemonize(pidfile, home)
81
setup_logging(home, foreground=foreground)
35
sys.stderr.write('\n')
36
sys.stderr.write('Launching loggerhead into the background.\n')
37
sys.stderr.write('PID file: %s\n' % (pidfile,))
38
sys.stderr.write('\n')
40
from loggerhead.daemon import daemonize
41
daemonize(pidfile, home)
43
# i hate that stupid logging config format, so just set up logging here.
46
log_folder = os.path.join(home, 'logs')
47
if not os.path.exists(log_folder):
50
f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s',
52
debug_log = logging.FileHandler(os.path.join(log_folder, 'debug.log'))
53
debug_log.setLevel(logging.DEBUG)
54
debug_log.setFormatter(f)
55
f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s',
57
access_log = logging.FileHandler(os.path.join(log_folder, 'access.log'))
58
access_log.setLevel(logging.INFO)
59
access_log.setFormatter(f)
61
logging.getLogger('').addHandler(debug_log)
62
logging.getLogger('turbogears.access').addHandler(access_log)
63
logging.getLogger('turbogears.controllers').setLevel(logging.INFO)
83
65
log = logging.getLogger('loggerhead')
84
66
log.info('Starting up...')
86
68
from loggerhead.controllers import Root
90
70
# re-index every 6 hours
92
index_freq = config.get('cache_rebuild_frequency', 6 * 3600)
93
72
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild)
96
75
turbogears.start_server(Root)
98
77
log.info('Shutdown.')