aboutsummaryrefslogtreecommitdiffstats
path: root/server/alias.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/alias.py')
-rw-r--r--server/alias.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/server/alias.py b/server/alias.py
index 8d75ec2..30925e1 100644
--- a/server/alias.py
+++ b/server/alias.py
@@ -55,25 +55,37 @@ if __name__ == '__main__':
if config.pidfile is None:
config.pidfile = os.path.join('/var/run/', config.name + '.pid')
- #set up the logger
- handler = logging.FileHandler(config.logfile)
+ #set up the root logger
+ logging.getLogger('').setLevel(args.debug)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
- handler.setFormatter(formatter)
+ if config.background:
+ #save logs in a file
+ fh = logging.FileHandler(config.logfile)
+ fh.setFormatter(formatter)
+ logging.getLogger('').addHandler(fh)
+ else:
+ #save logs to the console
+ ch = logging.StreamHandler()
+ ch.setFormatter(formatter)
+ logging.getLogger('').addHandler(ch)
+
+ if config.background:
+ context = daemon.DaemonContext(detach_process = True,
+ pidfile = daemon.pidfile.TimeoutPIDLockFile(config.pidfile,10),
+ files_preserve=[fh.stream.fileno()],
+ working_directory=os.path.abspath(config.root),
+ stdout=sys.stdout, stderr=sys.stderr)
+ else:
+ context = daemon.DaemonContext(detach_process = False,
+ stdout=sys.stdout, stderr=sys.stderr,
+ working_directory=os.path.abspath(config.root))
- logger = logging.getLogger("alias")
- logger.setLevel(args.debug)
- logger.addHandler(handler)
- import pdb; pdb.set_trace()
- context = daemon.DaemonContext(detach_process = config.background,
- pidfile = daemon.pidfile.TimeoutPIDLockFile(config.pidfile,10),
- files_preserve=[handler.stream.fileno()],
- stdout=sys.stdout, stderr=sys.stderr)
with context:
component = ObjectComponent(config.name, config.secret,
config.host, config.port,
config.root)
if component.connect():
- logger.info('Component {} connected'.format(component.boundjid))
+ logging.info('Component {} connected'.format(component.boundjid))
component.process(False)
else:
- logger.error("Component {} couldn't connect".format(component.boundjid))
+ logging.error("Component {} couldn't connect".format(component.boundjid))