diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-10-12 17:07:54 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-10-12 17:07:54 (GMT) |
commit | d5bb26e784bca318c30ea79abc84e57be1e47fc5 (patch) | |
tree | 4dd8c22cf36b9534422001b206db876da68cce54 | |
parent | f6cac3e333dc0846d425e6caba845158fbd25aee (diff) | |
parent | 4531447259b6c851f665a705e886fff329fef218 (diff) |
Merge branch 'master' of git+ssh://dev.laptop.org/git/projects/datastore
-rw-r--r-- | NEWS | 5 | ||||
-rwxr-xr-x | bin/datastore-service | 21 | ||||
-rw-r--r-- | src/olpc/datastore/Makefile.am | 1 | ||||
-rw-r--r-- | src/olpc/datastore/logger.py | 52 |
4 files changed, 64 insertions, 15 deletions
@@ -1,3 +1,8 @@ +Snapshot cb0acdf653 + +* Support for external properties. (bcsaller) +* Better logging. (marco) + Snapshot b603f340b2 * Request binary data as dbus.ByteArray. (tomeu) diff --git a/bin/datastore-service b/bin/datastore-service index 758ca45..1a62dfc 100755 --- a/bin/datastore-service +++ b/bin/datastore-service @@ -3,7 +3,7 @@ import sys, os, signal import gobject import dbus.service import dbus.mainloop.glib -from olpc.datastore import DataStore, DS_LOG_CHANNEL, backingstore +from olpc.datastore import DataStore, backingstore, logger import logging # Path handling @@ -20,16 +20,7 @@ if not os.path.exists(log_dir): os.makedirs(log_dir) #os.chdir(repo_dir) # setup logger -filename = None -if not sys.stdin.isatty(): - filename = os.path.join(log_dir, "datastore.log") - -logging.basicConfig(level=logging.WARNING, - format="%(asctime)-15s %(levelname)s: %(message)s", - filename = filename, - ) -# disable subsystem logging except where critical -logger = logging.getLogger(DS_LOG_CHANNEL) +logger.start('datastore') # check for old lockfiles, the rules here are that we can't be # connected to a tty. If we are not then in all likelyhood the process @@ -51,7 +42,7 @@ ds.registerBackend(backingstore.FileBackingStore) ds.registerBackend(backingstore.InplaceFileBackingStore) # and run it -logger.info("Starting Datastore %s" % (repo_dir)) +logging.info("Starting Datastore %s" % (repo_dir)) mainloop = gobject.MainLoop() def handle_disconnect(): @@ -91,10 +82,10 @@ def main(): time.sleep(0.0025) except KeyboardInterrupt: - logger.info("DataStore shutdown by user") + logging.info("DataStore shutdown by user") except: - logger.debug("Datastore shutdown with error", - exc_info=sys.exc_info()) + logging.debug("Datastore shutdown with error", + exc_info=sys.exc_info()) main() diff --git a/src/olpc/datastore/Makefile.am b/src/olpc/datastore/Makefile.am index 480a5a7..e32b314 100644 --- a/src/olpc/datastore/Makefile.am +++ b/src/olpc/datastore/Makefile.am @@ -5,6 +5,7 @@ datastore_PYTHON = \ bin_copy.py \ converter.py \ datastore.py \ + logger.py \ model.py \ xapianindex.py \ utils.py \ diff --git a/src/olpc/datastore/logger.py b/src/olpc/datastore/logger.py new file mode 100644 index 0000000..d1c9080 --- /dev/null +++ b/src/olpc/datastore/logger.py @@ -0,0 +1,52 @@ +# Copyright (C) 2007 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import sys +import os +import logging +import time + +# Let's keep this self contained so that it can be easily +# pasted in external sugar service like the datastore. + +def get_logs_dir(): + profile = os.environ.get('SUGAR_PROFILE', 'default') + logs_dir = os.path.join(os.path.expanduser('~'), + '.sugar', profile, 'logs') + return logs_dir + +def set_level(level): + levels = { 'error' : logging.ERROR, + 'warning' : logging.WARNING, + 'debug' : logging.DEBUG, + 'info' : logging.INFO } + if levels.has_key(level): + logging.getLogger('').setLevel(levels[level]) + +def start(log_filename=None): + logging.basicConfig(level=logging.WARNING, + format="%(created)f %(levelname)s %(message)s") + + if os.environ.has_key('SUGAR_LOGGER_LEVEL'): + set_level(os.environ['SUGAR_LOGGER_LEVEL']) + + if log_filename and not sys.stdin.isatty(): + log_path = os.path.join(get_logs_dir(), log_filename + '.log') + log_file = open(log_path, 'w') + + os.dup2(log_file.fileno(), sys.stdout.fileno()) + os.dup2(log_file.fileno(), sys.stderr.fileno()) |