Commit 8c0551e5 authored by Brian Moe's avatar Brian Moe

Incorporated Leo Singer's logging patch.

parent 009c9a3c
# Copyright (C) 2012 LIGO Scientific Collaboration
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program 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 General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Some convenience logging classes courtesy of Leo Singer, provided as is.
Usage:
import logging
import ligo.gracedb.rest
import ligo.gracedb.logger
import ligo.gracedb.logging
logging.basicConfig()
log = logging.getLogger('testing')
......@@ -13,7 +30,7 @@ log = logging.getLogger('testing')
gracedb = ligo.gracedb.rest.GraceDb()
graceid = 'T62829'
log.addHandler(ligo.gracedb.logger.GraceDbLogHandler(gracedb, graceid))
log.addHandler(ligo.gracedb.logging.GraceDbLogHandler(gracedb, graceid))
# The following will create a log entry on the gracedb server
# (if the log level permits)
......@@ -21,7 +38,12 @@ log.addHandler(ligo.gracedb.logger.GraceDbLogHandler(gracedb, graceid))
log.warn("this is a warning")
"""
import logging
# Perform explicit absolute import of Python standard library logging module.
# 'import logging' would not work here, because it would be interpreted as this
# module itself.
# module itself.g
logging = __import__('logging', level=0)
class GraceDbLogStream(object):
def __init__(self, gracedb, graceid):
......
......@@ -197,7 +197,7 @@ class TestGracedb(unittest.TestCase):
def test_logger(self):
import logging
import ligo.gracedb.rest
import ligo.gracedb.logger
import ligo.gracedb.logging
logging.basicConfig()
log = logging.getLogger('testing')
......@@ -206,7 +206,7 @@ class TestGracedb(unittest.TestCase):
#gracedb = ligo.gracedb.rest.GraceDb()
graceid = eventId
log.addHandler(ligo.gracedb.logger.GraceDbLogHandler(gracedb, graceid))
log.addHandler(ligo.gracedb.logging.GraceDbLogHandler(gracedb, graceid))
message = "Message is {0}".format(random.random())
log.warn(message)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment