aboutsummaryrefslogtreecommitdiffstats
path: root/server/alias.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-04-25 22:39:39 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2011-04-25 22:39:39 -0400
commite86e2048a124a1c4abf16712b548d7e7d7815ca3 (patch)
tree6be670f5fea86aabef2b6b172d22a53383a4d754 /server/alias.py
parent5f2d5dbc45f1bb84c3f58078cb132e0992ec0994 (diff)
downloadalias-e86e2048a124a1c4abf16712b548d7e7d7815ca3.tar.gz
Final cleanup of the logging system
- set up a root logger, which is going to catch all the other logger instances set up by other modules (sleekxmpp for instance) - by default, if not in background mode, everything gets logged to the console.
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))