Skip to content

Commit

Permalink
Add log.warning compatibility routine
Browse files Browse the repository at this point in the history
Python logging has deprecating logging.warn and preferrs
logging.warning.  This change adds lsst.log.warning to
enable both forms to reduce cognitive dissonance between
the two logging packages.
  • Loading branch information
timj committed Feb 5, 2019
1 parent d49bf57 commit 6f2f353
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions python/lsst/log/log/logContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def info(self, fmt, *args):
def warn(self, fmt, *args):
self._log(Log.WARN, False, fmt, *args)

def warning(self, fmt, *args):
self.warn(fmt, *args)

def error(self, fmt, *args):
self._log(Log.ERROR, False, fmt, *args)

Expand Down Expand Up @@ -192,6 +195,10 @@ def warn(fmt, *args):
Log.getDefaultLogger()._log(WARN, False, fmt, *args)


def warning(fmt, *args):
warn(fmt, *args)


def error(fmt, *args):
Log.getDefaultLogger()._log(ERROR, False, fmt, *args)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def testBasic(self):
log.warn("This is WARN")
log.error("This is ERROR")
log.fatal("This is FATAL")
log.warn("Format %d %g %s", 3, 2.71828, "foo")
log.warning("Format %d %g %s", 3, 2.71828, "foo")
self.check("""
root INFO: This is INFO
root INFO: This is unicode INFO
Expand Down Expand Up @@ -609,7 +609,7 @@ def testForwardToPythonContextManager(self):

# Without forwarding we only get python logger messages captured
with self.assertLogs(level="WARNING") as cm:
log.warn("lsst.log: not forwarded")
log.warning("lsst.log: not forwarded")
logging.warning("Python logging: captured")
self.assertEqual(len(cm.output), 1)

Expand Down

0 comments on commit 6f2f353

Please sign in to comment.